This commit is contained in:
21
node_modules/volar-service-css/LICENSE
generated
vendored
Normal file
21
node_modules/volar-service-css/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022-present Johnson Chu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
25
node_modules/volar-service-css/README.md
generated
vendored
Normal file
25
node_modules/volar-service-css/README.md
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
# volar-service-css
|
||||
|
||||
Volar plugin for [`vscode-css-languageservice`](https://github.com/microsoft/vscode-css-languageservice).
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install volar-service-css
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
`volar.config.js`
|
||||
|
||||
```js
|
||||
module.exports = {
|
||||
services: [
|
||||
require('volar-service-css').create(),
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE) © [Johnson Chu](https://github.com/johnsoncodehk)
|
||||
22
node_modules/volar-service-css/index.d.ts
generated
vendored
Normal file
22
node_modules/volar-service-css/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { Disposable, DocumentSelector, FormattingOptions, ProviderResult, LanguageServiceContext, LanguageServicePlugin } from '@volar/language-service';
|
||||
import * as css from 'vscode-css-languageservice';
|
||||
import { TextDocument } from 'vscode-languageserver-textdocument';
|
||||
import { URI } from 'vscode-uri';
|
||||
export interface Provide {
|
||||
'css/stylesheet': (document: TextDocument, ls: css.LanguageService) => css.Stylesheet;
|
||||
'css/languageService': (document: TextDocument) => css.LanguageService | undefined;
|
||||
}
|
||||
export declare function resolveReference(ref: string, baseUri: URI, workspaceFolders: URI[]): string;
|
||||
export declare function create({ cssDocumentSelector, scssDocumentSelector, lessDocumentSelector, useDefaultDataProvider, getDocumentContext, isFormattingEnabled, getFormattingOptions, getLanguageSettings, getCustomData, onDidChangeCustomData, }?: {
|
||||
cssDocumentSelector?: DocumentSelector;
|
||||
scssDocumentSelector?: DocumentSelector;
|
||||
lessDocumentSelector?: DocumentSelector;
|
||||
useDefaultDataProvider?: boolean;
|
||||
getDocumentContext?(context: LanguageServiceContext): css.DocumentContext;
|
||||
isFormattingEnabled?(document: TextDocument, context: LanguageServiceContext): ProviderResult<boolean>;
|
||||
getFormattingOptions?(document: TextDocument, options: FormattingOptions, context: LanguageServiceContext): ProviderResult<css.CSSFormatConfiguration>;
|
||||
getLanguageSettings?(document: TextDocument, context: LanguageServiceContext): ProviderResult<css.LanguageSettings | undefined>;
|
||||
getCustomData?(context: LanguageServiceContext): ProviderResult<css.ICSSDataProvider[]>;
|
||||
onDidChangeCustomData?(listener: () => void, context: LanguageServiceContext): Disposable;
|
||||
}): LanguageServicePlugin;
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
375
node_modules/volar-service-css/index.js
generated
vendored
Normal file
375
node_modules/volar-service-css/index.js
generated
vendored
Normal file
@@ -0,0 +1,375 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.resolveReference = resolveReference;
|
||||
exports.create = create;
|
||||
const css = require("vscode-css-languageservice");
|
||||
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
function resolveReference(ref, baseUri, workspaceFolders) {
|
||||
if (ref.match(/^\w[\w\d+.-]*:/)) {
|
||||
// starts with a schema
|
||||
return ref;
|
||||
}
|
||||
if (ref[0] === '/') { // resolve absolute path against the current workspace folder
|
||||
const folderUri = getRootFolder();
|
||||
if (folderUri) {
|
||||
return folderUri + ref.substr(1);
|
||||
}
|
||||
}
|
||||
const baseUriDir = baseUri.path.endsWith('/') ? baseUri : vscode_uri_1.Utils.dirname(baseUri);
|
||||
return vscode_uri_1.Utils.resolvePath(baseUriDir, ref).toString(true);
|
||||
function getRootFolder() {
|
||||
for (const folder of workspaceFolders) {
|
||||
let folderURI = folder.toString();
|
||||
if (!folderURI.endsWith('/')) {
|
||||
folderURI = folderURI + '/';
|
||||
}
|
||||
if (baseUri.toString().startsWith(folderURI)) {
|
||||
return folderURI;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function create({ cssDocumentSelector = ['css'], scssDocumentSelector = ['scss'], lessDocumentSelector = ['less'], useDefaultDataProvider = true, getDocumentContext = context => {
|
||||
return {
|
||||
resolveReference(ref, base) {
|
||||
let baseUri = vscode_uri_1.URI.parse(base);
|
||||
const decoded = context.decodeEmbeddedDocumentUri(baseUri);
|
||||
if (decoded) {
|
||||
baseUri = decoded[0];
|
||||
}
|
||||
return resolveReference(ref, baseUri, context.env.workspaceFolders);
|
||||
},
|
||||
};
|
||||
}, isFormattingEnabled = async (document, context) => {
|
||||
return await context.env.getConfiguration?.(document.languageId + '.format.enable') ?? true;
|
||||
}, getFormattingOptions = async (document, options, context) => {
|
||||
return {
|
||||
...options,
|
||||
...await context.env.getConfiguration?.(document.languageId + '.format'),
|
||||
};
|
||||
}, getLanguageSettings = async (document, context) => {
|
||||
return await context.env.getConfiguration?.(document.languageId);
|
||||
}, getCustomData = async (context) => {
|
||||
const customData = await context.env.getConfiguration?.('css.customData') ?? [];
|
||||
const newData = [];
|
||||
for (const customDataPath of customData) {
|
||||
for (const workspaceFolder of context.env.workspaceFolders) {
|
||||
const uri = vscode_uri_1.Utils.resolvePath(workspaceFolder, customDataPath);
|
||||
const json = await context.env.fs?.readFile?.(uri);
|
||||
if (json) {
|
||||
try {
|
||||
const data = JSON.parse(json);
|
||||
newData.push(css.newCSSDataProvider(data));
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return newData;
|
||||
}, onDidChangeCustomData = (listener, context) => {
|
||||
const disposable = context.env.onDidChangeConfiguration?.(listener);
|
||||
return {
|
||||
dispose() {
|
||||
disposable?.dispose();
|
||||
},
|
||||
};
|
||||
}, } = {}) {
|
||||
return {
|
||||
name: 'css',
|
||||
capabilities: {
|
||||
completionProvider: {
|
||||
// https://github.com/microsoft/vscode/blob/09850876e652688fb142e2e19fd00fd38c0bc4ba/extensions/css-language-features/server/src/cssServer.ts#L97
|
||||
triggerCharacters: ['/', '-', ':'],
|
||||
},
|
||||
renameProvider: {
|
||||
prepareProvider: true,
|
||||
},
|
||||
codeActionProvider: {},
|
||||
definitionProvider: true,
|
||||
diagnosticProvider: {
|
||||
interFileDependencies: false,
|
||||
workspaceDiagnostics: false,
|
||||
},
|
||||
hoverProvider: true,
|
||||
referencesProvider: true,
|
||||
documentHighlightProvider: true,
|
||||
documentLinkProvider: {},
|
||||
documentSymbolProvider: true,
|
||||
colorProvider: true,
|
||||
foldingRangeProvider: true,
|
||||
selectionRangeProvider: true,
|
||||
documentFormattingProvider: true,
|
||||
},
|
||||
create(context) {
|
||||
const stylesheets = new WeakMap();
|
||||
const fileSystemProvider = {
|
||||
stat: async (uri) => await context.env.fs?.stat(vscode_uri_1.URI.parse(uri))
|
||||
?? { type: css.FileType.Unknown, ctime: 0, mtime: 0, size: 0 },
|
||||
readDirectory: async (uri) => await context.env.fs?.readDirectory(vscode_uri_1.URI.parse(uri)) ?? [],
|
||||
};
|
||||
const documentContext = getDocumentContext(context);
|
||||
const disposable = onDidChangeCustomData(() => initializing = undefined, context);
|
||||
let cssLs;
|
||||
let scssLs;
|
||||
let lessLs;
|
||||
let customData = [];
|
||||
let initializing;
|
||||
return {
|
||||
dispose() {
|
||||
disposable.dispose();
|
||||
},
|
||||
provide: {
|
||||
'css/stylesheet': getStylesheet,
|
||||
'css/languageService': getCssLs,
|
||||
},
|
||||
async provideCompletionItems(document, position) {
|
||||
return worker(document, async (stylesheet, cssLs) => {
|
||||
const settings = await getLanguageSettings(document, context);
|
||||
return await cssLs.doComplete2(document, position, stylesheet, documentContext, settings?.completion);
|
||||
});
|
||||
},
|
||||
provideRenameRange(document, position) {
|
||||
return worker(document, (stylesheet, cssLs) => {
|
||||
return cssLs.prepareRename(document, position, stylesheet);
|
||||
});
|
||||
},
|
||||
provideRenameEdits(document, position, newName) {
|
||||
return worker(document, (stylesheet, cssLs) => {
|
||||
return cssLs.doRename(document, position, newName, stylesheet);
|
||||
});
|
||||
},
|
||||
provideCodeActions(document, range, context) {
|
||||
return worker(document, (stylesheet, cssLs) => {
|
||||
return cssLs.doCodeActions2(document, range, context, stylesheet);
|
||||
});
|
||||
},
|
||||
provideDefinition(document, position) {
|
||||
return worker(document, (stylesheet, cssLs) => {
|
||||
const location = cssLs.findDefinition(document, position, stylesheet);
|
||||
if (location) {
|
||||
return [{
|
||||
targetUri: location.uri,
|
||||
targetRange: location.range,
|
||||
targetSelectionRange: location.range,
|
||||
}];
|
||||
}
|
||||
});
|
||||
},
|
||||
async provideDiagnostics(document) {
|
||||
return worker(document, async (stylesheet, cssLs) => {
|
||||
const settings = await getLanguageSettings(document, context);
|
||||
return cssLs.doValidation(document, stylesheet, settings);
|
||||
});
|
||||
},
|
||||
async provideHover(document, position) {
|
||||
return worker(document, async (stylesheet, cssLs) => {
|
||||
const settings = await getLanguageSettings(document, context);
|
||||
return cssLs.doHover(document, position, stylesheet, settings?.hover);
|
||||
});
|
||||
},
|
||||
provideReferences(document, position) {
|
||||
return worker(document, (stylesheet, cssLs) => {
|
||||
return cssLs.findReferences(document, position, stylesheet);
|
||||
});
|
||||
},
|
||||
provideDocumentHighlights(document, position) {
|
||||
return worker(document, (stylesheet, cssLs) => {
|
||||
return cssLs.findDocumentHighlights(document, position, stylesheet);
|
||||
});
|
||||
},
|
||||
async provideDocumentLinks(document) {
|
||||
return await worker(document, (stylesheet, cssLs) => {
|
||||
return cssLs.findDocumentLinks2(document, stylesheet, documentContext);
|
||||
});
|
||||
},
|
||||
provideDocumentSymbols(document) {
|
||||
return worker(document, (stylesheet, cssLs) => {
|
||||
return cssLs.findDocumentSymbols2(document, stylesheet);
|
||||
});
|
||||
},
|
||||
provideDocumentColors(document) {
|
||||
return worker(document, (stylesheet, cssLs) => {
|
||||
return cssLs.findDocumentColors(document, stylesheet);
|
||||
});
|
||||
},
|
||||
provideColorPresentations(document, color, range) {
|
||||
return worker(document, (stylesheet, cssLs) => {
|
||||
return cssLs.getColorPresentations(document, stylesheet, color, range);
|
||||
});
|
||||
},
|
||||
provideFoldingRanges(document) {
|
||||
return worker(document, (_stylesheet, cssLs) => {
|
||||
return cssLs.getFoldingRanges(document, context.env.clientCapabilities?.textDocument?.foldingRange);
|
||||
});
|
||||
},
|
||||
provideSelectionRanges(document, positions) {
|
||||
return worker(document, (stylesheet, cssLs) => {
|
||||
return cssLs.getSelectionRanges(document, positions, stylesheet);
|
||||
});
|
||||
},
|
||||
async provideDocumentFormattingEdits(document, formatRange, options, codeOptions) {
|
||||
return worker(document, async (_stylesheet, cssLs) => {
|
||||
if (!await isFormattingEnabled(document, context)) {
|
||||
return;
|
||||
}
|
||||
const formatOptions = await getFormattingOptions(document, options, context);
|
||||
let formatDocument = document;
|
||||
let prefixes = [];
|
||||
let suffixes = [];
|
||||
if (codeOptions?.initialIndentLevel) {
|
||||
for (let i = 0; i < codeOptions.initialIndentLevel; i++) {
|
||||
if (i === codeOptions.initialIndentLevel - 1) {
|
||||
prefixes.push('_', '{');
|
||||
suffixes.unshift('}');
|
||||
}
|
||||
else {
|
||||
prefixes.push('_', '{\n');
|
||||
suffixes.unshift('\n}');
|
||||
}
|
||||
}
|
||||
formatDocument = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version, prefixes.join('') + document.getText() + suffixes.join(''));
|
||||
formatRange = {
|
||||
start: formatDocument.positionAt(0),
|
||||
end: formatDocument.positionAt(formatDocument.getText().length),
|
||||
};
|
||||
}
|
||||
let edits = cssLs.format(formatDocument, formatRange, formatOptions);
|
||||
if (codeOptions) {
|
||||
let newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(formatDocument, edits);
|
||||
for (const prefix of prefixes) {
|
||||
newText = newText.trimStart().slice(prefix.trim().length);
|
||||
}
|
||||
for (const suffix of suffixes.reverse()) {
|
||||
newText = newText.trimEnd().slice(0, -suffix.trim().length);
|
||||
}
|
||||
if (!codeOptions.initialIndentLevel && codeOptions.level > 0) {
|
||||
newText = ensureNewLines(newText);
|
||||
}
|
||||
edits = [{
|
||||
range: {
|
||||
start: document.positionAt(0),
|
||||
end: document.positionAt(document.getText().length),
|
||||
},
|
||||
newText,
|
||||
}];
|
||||
}
|
||||
return edits;
|
||||
function ensureNewLines(newText) {
|
||||
const verifyDocument = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version, '_ {' + newText + '}');
|
||||
const verifyEdits = cssLs.format(verifyDocument, undefined, formatOptions);
|
||||
let verifyText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(verifyDocument, verifyEdits);
|
||||
verifyText = verifyText.trimStart().slice('_'.length);
|
||||
verifyText = verifyText.trim().slice('{'.length, -'}'.length);
|
||||
if (startWithNewLine(verifyText) !== startWithNewLine(newText)) {
|
||||
if (startWithNewLine(verifyText)) {
|
||||
newText = '\n' + newText;
|
||||
}
|
||||
else if (newText.startsWith('\n')) {
|
||||
newText = newText.slice(1);
|
||||
}
|
||||
else if (newText.startsWith('\r\n')) {
|
||||
newText = newText.slice(2);
|
||||
}
|
||||
}
|
||||
if (endWithNewLine(verifyText) !== endWithNewLine(newText)) {
|
||||
if (endWithNewLine(verifyText)) {
|
||||
newText = newText + '\n';
|
||||
}
|
||||
else if (newText.endsWith('\n')) {
|
||||
newText = newText.slice(0, -1);
|
||||
}
|
||||
else if (newText.endsWith('\r\n')) {
|
||||
newText = newText.slice(0, -2);
|
||||
}
|
||||
}
|
||||
return newText;
|
||||
}
|
||||
function startWithNewLine(text) {
|
||||
return text.startsWith('\n') || text.startsWith('\r\n');
|
||||
}
|
||||
function endWithNewLine(text) {
|
||||
return text.endsWith('\n') || text.endsWith('\r\n');
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
function getCssLs(document) {
|
||||
if (matchDocument(cssDocumentSelector, document)) {
|
||||
if (!cssLs) {
|
||||
cssLs = css.getCSSLanguageService({
|
||||
fileSystemProvider,
|
||||
clientCapabilities: context.env.clientCapabilities,
|
||||
useDefaultDataProvider,
|
||||
customDataProviders: customData,
|
||||
});
|
||||
cssLs.setDataProviders(useDefaultDataProvider, customData);
|
||||
}
|
||||
return cssLs;
|
||||
}
|
||||
else if (matchDocument(scssDocumentSelector, document)) {
|
||||
if (!scssLs) {
|
||||
scssLs = css.getSCSSLanguageService({
|
||||
fileSystemProvider,
|
||||
clientCapabilities: context.env.clientCapabilities,
|
||||
useDefaultDataProvider,
|
||||
customDataProviders: customData,
|
||||
});
|
||||
scssLs.setDataProviders(useDefaultDataProvider, customData);
|
||||
}
|
||||
return scssLs;
|
||||
}
|
||||
else if (matchDocument(lessDocumentSelector, document)) {
|
||||
if (!lessLs) {
|
||||
lessLs = css.getLESSLanguageService({
|
||||
fileSystemProvider,
|
||||
clientCapabilities: context.env.clientCapabilities,
|
||||
useDefaultDataProvider,
|
||||
customDataProviders: customData,
|
||||
});
|
||||
lessLs.setDataProviders(useDefaultDataProvider, customData);
|
||||
}
|
||||
return lessLs;
|
||||
}
|
||||
}
|
||||
async function worker(document, callback) {
|
||||
const cssLs = getCssLs(document);
|
||||
if (!cssLs) {
|
||||
return;
|
||||
}
|
||||
await (initializing ??= initialize());
|
||||
return callback(getStylesheet(document, cssLs), cssLs);
|
||||
}
|
||||
function getStylesheet(document, ls) {
|
||||
const cache = stylesheets.get(document);
|
||||
if (cache) {
|
||||
const [cacheVersion, cacheStylesheet] = cache;
|
||||
if (cacheVersion === document.version) {
|
||||
return cacheStylesheet;
|
||||
}
|
||||
}
|
||||
const stylesheet = ls.parseStylesheet(document);
|
||||
stylesheets.set(document, [document.version, stylesheet]);
|
||||
return stylesheet;
|
||||
}
|
||||
async function initialize() {
|
||||
customData = await getCustomData(context);
|
||||
cssLs?.setDataProviders(useDefaultDataProvider, customData);
|
||||
scssLs?.setDataProviders(useDefaultDataProvider, customData);
|
||||
lessLs?.setDataProviders(useDefaultDataProvider, customData);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
function matchDocument(selector, document) {
|
||||
for (const sel of selector) {
|
||||
if (sel === document.languageId || (typeof sel === 'object' && sel.language === document.languageId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
43
node_modules/volar-service-css/package.json
generated
vendored
Normal file
43
node_modules/volar-service-css/package.json
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "volar-service-css",
|
||||
"version": "0.0.62",
|
||||
"description": "Integrate vscode-css-languageservice into Volar",
|
||||
"homepage": "https://github.com/volarjs/services/tree/master/packages/css",
|
||||
"bugs": "https://github.com/volarjs/services/issues",
|
||||
"sideEffects": false,
|
||||
"keywords": [
|
||||
"volar-service"
|
||||
],
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"**/*.js",
|
||||
"**/*.d.ts"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/volarjs/services.git",
|
||||
"directory": "packages/css"
|
||||
},
|
||||
"author": {
|
||||
"name": "Johnson Chu",
|
||||
"email": "johnsoncodehk@gmail.com",
|
||||
"url": "https://github.com/johnsoncodehk"
|
||||
},
|
||||
"dependencies": {
|
||||
"vscode-css-languageservice": "^6.3.0",
|
||||
"vscode-languageserver-textdocument": "^1.0.11",
|
||||
"vscode-uri": "^3.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@volar/language-service": "~2.4.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@volar/language-service": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"gitHead": "f1ddbdc4d9df0772db5a0d46ff8ff64eecc9de02"
|
||||
}
|
||||
Reference in New Issue
Block a user