This commit is contained in:
21
node_modules/@volar/kit/LICENSE
generated
vendored
Normal file
21
node_modules/@volar/kit/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-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.
|
||||
98
node_modules/@volar/kit/README.md
generated
vendored
Normal file
98
node_modules/@volar/kit/README.md
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
# Kit
|
||||
|
||||
## Example: Use FileWatcher
|
||||
|
||||
```ts
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { watch } from 'chokidar';
|
||||
import * as kit from '@volar/kit';
|
||||
|
||||
const tsconfig = getTsconfig();
|
||||
const project = kit.createProject(tsconfig, [{ extension: 'foo', isMixedContent: true, scriptKind: 7 }]);
|
||||
const config: kit.Config = {
|
||||
languages: {
|
||||
// ...
|
||||
},
|
||||
services: {
|
||||
// ...
|
||||
},
|
||||
};
|
||||
const linter = kit.createLinter(config, project.languageServiceHost);
|
||||
|
||||
let req = 0;
|
||||
|
||||
update();
|
||||
|
||||
createWatcher(path.dirname(tsconfig), ['ts', 'js', 'foo'])
|
||||
.on('add', (fileName) => {
|
||||
project.fileCreated(fileName);
|
||||
update();
|
||||
})
|
||||
.on('unlink', (fileName) => {
|
||||
project.fileDeleted(fileName);
|
||||
update();
|
||||
})
|
||||
.on('change', (fileName) => {
|
||||
project.fileUpdated(fileName);
|
||||
update();
|
||||
});
|
||||
|
||||
function createWatcher(rootPath: string, extension: string[]) {
|
||||
return watch(`${rootPath}/**/*.{${extension.join(',')}}`, {
|
||||
ignored: (path) => path.includes('node_modules'),
|
||||
ignoreInitial: true
|
||||
});
|
||||
}
|
||||
|
||||
async function update() {
|
||||
|
||||
const currentReq = ++req;
|
||||
const isCanceled = () => currentReq !== req;
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
if (isCanceled()) return;
|
||||
|
||||
process.stdout.write('\x1Bc'); // clear console
|
||||
|
||||
let hasError = false;
|
||||
for (const fileName of project.languageServiceHost.getScriptFileNames()) {
|
||||
const errors = await linter.check(fileName);
|
||||
if (isCanceled()) return;
|
||||
if (errors.length) {
|
||||
linter.logErrors(fileName, errors);
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
if (!hasError) {
|
||||
console.log('No errors');
|
||||
}
|
||||
}
|
||||
|
||||
function getTsconfig() {
|
||||
|
||||
let tsconfig = path.resolve(process.cwd(), './tsconfig.json');
|
||||
|
||||
const tsconfigIndex = process.argv.indexOf('--tsconfig');
|
||||
if (tsconfigIndex >= 0) {
|
||||
tsconfig = path.resolve(process.cwd(), process.argv[tsconfigIndex + 1]);
|
||||
}
|
||||
|
||||
if (!fs.existsSync(tsconfig)) {
|
||||
throw `tsconfig.json not found: ${tsconfig}`;
|
||||
}
|
||||
|
||||
return tsconfig;
|
||||
}
|
||||
```
|
||||
|
||||
## Create Project without tsconfig.json
|
||||
|
||||
```ts
|
||||
const rootPath = process.cwd();
|
||||
const fileNames = [
|
||||
path.resolve(rootPath, './src/a.ts'),
|
||||
path.resolve(rootPath, './src/b.js'),
|
||||
path.resolve(rootPath, './src/c.foo'),
|
||||
];
|
||||
const project = kit.createInferredProject(rootPath, fileNames);
|
||||
```
|
||||
3
node_modules/@volar/kit/index.d.ts
generated
vendored
Normal file
3
node_modules/@volar/kit/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from '@volar/language-service';
|
||||
export * from './lib/createFormatter';
|
||||
export * from './lib/createChecker';
|
||||
20
node_modules/@volar/kit/index.js
generated
vendored
Normal file
20
node_modules/@volar/kit/index.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("@volar/language-service"), exports);
|
||||
__exportStar(require("./lib/createFormatter"), exports);
|
||||
__exportStar(require("./lib/createChecker"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
31
node_modules/@volar/kit/lib/createChecker.d.ts
generated
vendored
Normal file
31
node_modules/@volar/kit/lib/createChecker.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Diagnostic, Language, LanguagePlugin, LanguageServicePlugin, ProjectContext } from '@volar/language-service';
|
||||
import * as ts from 'typescript';
|
||||
import { URI } from 'vscode-uri';
|
||||
export declare function createTypeScriptChecker(languagePlugins: LanguagePlugin<URI>[], languageServicePlugins: LanguageServicePlugin[], tsconfig: string, includeProjectReference?: boolean, setup?: (options: {
|
||||
language: Language;
|
||||
project: ProjectContext;
|
||||
}) => void): {
|
||||
check: (fileName: string) => Promise<Diagnostic[]>;
|
||||
fixErrors: (fileName: string, diagnostics: Diagnostic[], only: string[] | undefined, writeFile: (fileName: string, newText: string) => Promise<void>) => Promise<void>;
|
||||
printErrors: (fileName: string, diagnostics: Diagnostic[], rootPath?: string) => string;
|
||||
getRootFileNames: () => string[];
|
||||
language: Language<URI>;
|
||||
settings: {};
|
||||
fileCreated(fileName: string): void;
|
||||
fileUpdated(fileName: string): void;
|
||||
fileDeleted(fileName: string): void;
|
||||
};
|
||||
export declare function createTypeScriptInferredChecker(languagePlugins: LanguagePlugin<URI>[], languageServicePlugins: LanguageServicePlugin[], getScriptFileNames: () => string[], compilerOptions?: ts.CompilerOptions, setup?: (options: {
|
||||
language: Language;
|
||||
project: ProjectContext;
|
||||
}) => void): {
|
||||
check: (fileName: string) => Promise<Diagnostic[]>;
|
||||
fixErrors: (fileName: string, diagnostics: Diagnostic[], only: string[] | undefined, writeFile: (fileName: string, newText: string) => Promise<void>) => Promise<void>;
|
||||
printErrors: (fileName: string, diagnostics: Diagnostic[], rootPath?: string) => string;
|
||||
getRootFileNames: () => string[];
|
||||
language: Language<URI>;
|
||||
settings: {};
|
||||
fileCreated(fileName: string): void;
|
||||
fileUpdated(fileName: string): void;
|
||||
fileDeleted(fileName: string): void;
|
||||
};
|
||||
309
node_modules/@volar/kit/lib/createChecker.js
generated
vendored
Normal file
309
node_modules/@volar/kit/lib/createChecker.js
generated
vendored
Normal file
@@ -0,0 +1,309 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createTypeScriptChecker = createTypeScriptChecker;
|
||||
exports.createTypeScriptInferredChecker = createTypeScriptInferredChecker;
|
||||
const language_service_1 = require("@volar/language-service");
|
||||
const typescript_1 = require("@volar/typescript");
|
||||
const path = require("typesafe-path/posix");
|
||||
const ts = require("typescript");
|
||||
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const createServiceEnvironment_1 = require("./createServiceEnvironment");
|
||||
const utils_1 = require("./utils");
|
||||
function createTypeScriptChecker(languagePlugins, languageServicePlugins, tsconfig, includeProjectReference = false, setup) {
|
||||
const tsconfigPath = (0, utils_1.asPosix)(tsconfig);
|
||||
return createTypeScriptCheckerWorker(languagePlugins, languageServicePlugins, tsconfigPath, () => {
|
||||
return ts.parseJsonSourceFileConfigFileContent(ts.readJsonConfigFile(tsconfigPath, ts.sys.readFile), ts.sys, path.dirname(tsconfigPath), undefined, tsconfigPath, undefined, languagePlugins.map(plugin => plugin.typescript?.extraFileExtensions ?? []).flat());
|
||||
}, includeProjectReference, setup);
|
||||
}
|
||||
function createTypeScriptInferredChecker(languagePlugins, languageServicePlugins, getScriptFileNames, compilerOptions = utils_1.defaultCompilerOptions, setup) {
|
||||
return createTypeScriptCheckerWorker(languagePlugins, languageServicePlugins, undefined, () => {
|
||||
return {
|
||||
options: compilerOptions,
|
||||
fileNames: getScriptFileNames(),
|
||||
errors: [],
|
||||
};
|
||||
}, false, setup);
|
||||
}
|
||||
const fsFileSnapshots = (0, language_service_1.createUriMap)();
|
||||
function createTypeScriptCheckerWorker(languagePlugins, languageServicePlugins, configFileName, getCommandLine, includeProjectReference, setup) {
|
||||
let settings = {};
|
||||
const didChangeWatchedFilesCallbacks = new Set();
|
||||
const env = (0, createServiceEnvironment_1.createServiceEnvironment)(() => settings);
|
||||
env.onDidChangeWatchedFiles = cb => {
|
||||
didChangeWatchedFilesCallbacks.add(cb);
|
||||
return {
|
||||
dispose: () => {
|
||||
didChangeWatchedFilesCallbacks.delete(cb);
|
||||
},
|
||||
};
|
||||
};
|
||||
const language = (0, language_service_1.createLanguage)([
|
||||
...languagePlugins,
|
||||
{ getLanguageId: uri => (0, typescript_1.resolveFileLanguageId)(uri.path) },
|
||||
], (0, language_service_1.createUriMap)(ts.sys.useCaseSensitiveFileNames), (uri, includeFsFiles) => {
|
||||
if (!includeFsFiles) {
|
||||
return;
|
||||
}
|
||||
const cache = fsFileSnapshots.get(uri);
|
||||
const fileName = (0, utils_1.asFileName)(uri);
|
||||
const modifiedTime = ts.sys.getModifiedTime?.(fileName)?.valueOf();
|
||||
if (!cache || cache[0] !== modifiedTime) {
|
||||
if (ts.sys.fileExists(fileName)) {
|
||||
const text = ts.sys.readFile(fileName);
|
||||
const snapshot = text !== undefined ? ts.ScriptSnapshot.fromString(text) : undefined;
|
||||
fsFileSnapshots.set(uri, [modifiedTime, snapshot]);
|
||||
}
|
||||
else {
|
||||
fsFileSnapshots.set(uri, [modifiedTime, undefined]);
|
||||
}
|
||||
}
|
||||
const snapshot = fsFileSnapshots.get(uri)?.[1];
|
||||
if (snapshot) {
|
||||
language.scripts.set(uri, snapshot);
|
||||
}
|
||||
else {
|
||||
language.scripts.delete(uri);
|
||||
}
|
||||
});
|
||||
const [projectHost, languageService] = createTypeScriptCheckerLanguageService(env, language, languageServicePlugins, configFileName, getCommandLine, setup);
|
||||
const projectReferenceLanguageServices = new Map();
|
||||
if (includeProjectReference) {
|
||||
const tsconfigs = new Set();
|
||||
const tsLs = languageService.context.inject('typescript/languageService');
|
||||
const projectReferences = tsLs.getProgram()?.getResolvedProjectReferences();
|
||||
if (configFileName) {
|
||||
tsconfigs.add((0, utils_1.asPosix)(configFileName));
|
||||
}
|
||||
projectReferences?.forEach(visit);
|
||||
function visit(ref) {
|
||||
if (ref && !tsconfigs.has(ref.sourceFile.fileName)) {
|
||||
tsconfigs.add(ref.sourceFile.fileName);
|
||||
const projectReferenceLanguageService = createTypeScriptCheckerLanguageService(env, language, languageServicePlugins, ref.sourceFile.fileName, () => ref.commandLine, setup);
|
||||
projectReferenceLanguageServices.set(ref.sourceFile.fileName, projectReferenceLanguageService);
|
||||
ref.references?.forEach(visit);
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
// apis
|
||||
check,
|
||||
fixErrors,
|
||||
printErrors,
|
||||
getRootFileNames: () => {
|
||||
const fileNames = projectHost.getScriptFileNames();
|
||||
for (const [projectHost] of projectReferenceLanguageServices.values()) {
|
||||
fileNames.push(...projectHost.getScriptFileNames());
|
||||
}
|
||||
return [...new Set(fileNames)];
|
||||
},
|
||||
language,
|
||||
// settings
|
||||
get settings() {
|
||||
return settings;
|
||||
},
|
||||
set settings(v) {
|
||||
settings = v;
|
||||
},
|
||||
// file events
|
||||
fileCreated(fileName) {
|
||||
fileEvent(fileName, 1);
|
||||
},
|
||||
fileUpdated(fileName) {
|
||||
fileEvent(fileName, 2);
|
||||
},
|
||||
fileDeleted(fileName) {
|
||||
fileEvent(fileName, 3);
|
||||
},
|
||||
};
|
||||
function fileEvent(fileName, type) {
|
||||
fileName = (0, utils_1.asPosix)(fileName);
|
||||
for (const cb of didChangeWatchedFilesCallbacks) {
|
||||
cb({ changes: [{ uri: (0, utils_1.asUri)(fileName).toString(), type }] });
|
||||
}
|
||||
}
|
||||
function check(fileName) {
|
||||
fileName = (0, utils_1.asPosix)(fileName);
|
||||
const uri = (0, utils_1.asUri)(fileName);
|
||||
const languageService = getLanguageServiceForFile(fileName);
|
||||
return languageService.getDiagnostics(uri);
|
||||
}
|
||||
async function fixErrors(fileName, diagnostics, only, writeFile) {
|
||||
fileName = (0, utils_1.asPosix)(fileName);
|
||||
const uri = (0, utils_1.asUri)(fileName);
|
||||
const languageService = getLanguageServiceForFile(fileName);
|
||||
const sourceScript = languageService.context.language.scripts.get(uri);
|
||||
if (sourceScript) {
|
||||
const document = languageService.context.documents.get(uri, sourceScript.languageId, sourceScript.snapshot);
|
||||
const range = { start: document.positionAt(0), end: document.positionAt(document.getText().length) };
|
||||
const codeActions = await languageService.getCodeActions(uri, range, { diagnostics, only, triggerKind: 1 });
|
||||
if (codeActions) {
|
||||
for (let i = 0; i < codeActions.length; i++) {
|
||||
codeActions[i] = await languageService.resolveCodeAction(codeActions[i]);
|
||||
}
|
||||
const edits = codeActions.map(codeAction => codeAction.edit).filter((edit) => !!edit);
|
||||
if (edits.length) {
|
||||
const rootEdit = edits[0];
|
||||
(0, language_service_1.mergeWorkspaceEdits)(rootEdit, ...edits.slice(1));
|
||||
for (const uri in rootEdit.changes ?? {}) {
|
||||
const edits = rootEdit.changes[uri];
|
||||
if (edits.length) {
|
||||
const parsedUri = vscode_uri_1.URI.parse(uri);
|
||||
const editFile = languageService.context.language.scripts.get(parsedUri);
|
||||
if (editFile) {
|
||||
const editDocument = languageService.context.documents.get(parsedUri, editFile.languageId, editFile.snapshot);
|
||||
const newString = vscode_languageserver_textdocument_1.TextDocument.applyEdits(editDocument, edits);
|
||||
await writeFile((0, utils_1.asFileName)(parsedUri), newString);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const change of rootEdit.documentChanges ?? []) {
|
||||
if ('textDocument' in change) {
|
||||
const changeUri = vscode_uri_1.URI.parse(change.textDocument.uri);
|
||||
const editFile = languageService.context.language.scripts.get(changeUri);
|
||||
if (editFile) {
|
||||
const editDocument = languageService.context.documents.get(changeUri, editFile.languageId, editFile.snapshot);
|
||||
const newString = vscode_languageserver_textdocument_1.TextDocument.applyEdits(editDocument, change.edits);
|
||||
await writeFile((0, utils_1.asFileName)(changeUri), newString);
|
||||
}
|
||||
}
|
||||
// TODO: CreateFile | RenameFile | DeleteFile
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function printErrors(fileName, diagnostics, rootPath = process.cwd()) {
|
||||
let text = formatErrors(fileName, diagnostics, rootPath);
|
||||
for (const diagnostic of diagnostics) {
|
||||
text = text.replace(`TS${diagnostic.code}`, (diagnostic.source ?? '') + (diagnostic.code ? `(${diagnostic.code})` : ''));
|
||||
}
|
||||
return text;
|
||||
}
|
||||
function formatErrors(fileName, diagnostics, rootPath) {
|
||||
fileName = (0, utils_1.asPosix)(fileName);
|
||||
const uri = (0, utils_1.asUri)(fileName);
|
||||
const languageService = getLanguageServiceForFile(fileName);
|
||||
const sourceScript = languageService.context.language.scripts.get(uri);
|
||||
const document = languageService.context.documents.get(uri, sourceScript.languageId, sourceScript.snapshot);
|
||||
const errors = diagnostics.map(diagnostic => ({
|
||||
category: diagnostic.severity === 1 ? ts.DiagnosticCategory.Error : ts.DiagnosticCategory.Warning,
|
||||
code: diagnostic.code,
|
||||
file: ts.createSourceFile(fileName, document.getText(), ts.ScriptTarget.JSON),
|
||||
start: document.offsetAt(diagnostic.range.start),
|
||||
length: document.offsetAt(diagnostic.range.end) - document.offsetAt(diagnostic.range.start),
|
||||
messageText: diagnostic.message,
|
||||
}));
|
||||
const text = ts.formatDiagnosticsWithColorAndContext(errors, {
|
||||
getCurrentDirectory: () => rootPath,
|
||||
getCanonicalFileName: fileName => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
|
||||
getNewLine: () => ts.sys.newLine,
|
||||
});
|
||||
return text;
|
||||
}
|
||||
function getLanguageServiceForFile(fileName) {
|
||||
if (!includeProjectReference) {
|
||||
return languageService;
|
||||
}
|
||||
fileName = (0, utils_1.asPosix)(fileName);
|
||||
for (const [_1, languageService] of projectReferenceLanguageServices.values()) {
|
||||
const tsLs = languageService.context.inject('typescript/languageService');
|
||||
if (tsLs.getProgram()?.getSourceFile(fileName)) {
|
||||
return languageService;
|
||||
}
|
||||
}
|
||||
return languageService;
|
||||
}
|
||||
}
|
||||
function createTypeScriptCheckerLanguageService(env, language, languageServicePlugins, configFileName, getCommandLine, setup) {
|
||||
let commandLine = getCommandLine();
|
||||
let projectVersion = 0;
|
||||
let shouldCheckRootFiles = false;
|
||||
const resolvedFileNameByCommandLine = new WeakMap();
|
||||
const projectHost = {
|
||||
getCurrentDirectory: () => env.workspaceFolders.length
|
||||
? (0, utils_1.asFileName)(env.workspaceFolders[0])
|
||||
: process.cwd(),
|
||||
getCompilationSettings: () => {
|
||||
return commandLine.options;
|
||||
},
|
||||
getProjectReferences: () => {
|
||||
return commandLine.projectReferences;
|
||||
},
|
||||
getProjectVersion: () => {
|
||||
checkRootFilesUpdate();
|
||||
return projectVersion.toString();
|
||||
},
|
||||
getScriptFileNames: () => {
|
||||
checkRootFilesUpdate();
|
||||
let fileNames = resolvedFileNameByCommandLine.get(commandLine);
|
||||
if (!fileNames) {
|
||||
fileNames = commandLine.fileNames.map(utils_1.asPosix);
|
||||
resolvedFileNameByCommandLine.set(commandLine, fileNames);
|
||||
}
|
||||
return fileNames;
|
||||
},
|
||||
};
|
||||
const project = {
|
||||
typescript: {
|
||||
configFileName,
|
||||
sys: ts.sys,
|
||||
uriConverter: {
|
||||
asFileName: utils_1.asFileName,
|
||||
asUri: utils_1.asUri,
|
||||
},
|
||||
...(0, typescript_1.createLanguageServiceHost)(ts, ts.sys, language, utils_1.asUri, projectHost),
|
||||
},
|
||||
};
|
||||
setup?.({ language, project });
|
||||
const languageService = (0, language_service_1.createLanguageService)(language, languageServicePlugins, env, project);
|
||||
env.onDidChangeWatchedFiles?.(({ changes }) => {
|
||||
const tsLs = languageService.context.inject('typescript/languageService');
|
||||
const program = tsLs.getProgram();
|
||||
for (const change of changes) {
|
||||
const changeUri = vscode_uri_1.URI.parse(change.uri);
|
||||
const fileName = (0, utils_1.asFileName)(changeUri);
|
||||
if (change.type === 2) {
|
||||
if (program?.getSourceFile(fileName)) {
|
||||
projectVersion++;
|
||||
}
|
||||
}
|
||||
else if (change.type === 3) {
|
||||
if (program?.getSourceFile(fileName)) {
|
||||
projectVersion++;
|
||||
shouldCheckRootFiles = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (change.type === 1) {
|
||||
shouldCheckRootFiles = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return [projectHost, languageService];
|
||||
function checkRootFilesUpdate() {
|
||||
if (!shouldCheckRootFiles) {
|
||||
return;
|
||||
}
|
||||
shouldCheckRootFiles = false;
|
||||
const newCommandLine = getCommandLine();
|
||||
if (!arrayItemsEqual(newCommandLine.fileNames, commandLine.fileNames)) {
|
||||
commandLine.fileNames = newCommandLine.fileNames;
|
||||
projectVersion++;
|
||||
}
|
||||
}
|
||||
}
|
||||
function arrayItemsEqual(a, b) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
const set = new Set(a);
|
||||
for (const file of b) {
|
||||
if (!set.has(file)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//# sourceMappingURL=createChecker.js.map
|
||||
7
node_modules/@volar/kit/lib/createFormatter.d.ts
generated
vendored
Normal file
7
node_modules/@volar/kit/lib/createFormatter.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { FormattingOptions, LanguagePlugin, LanguageServicePlugin } from '@volar/language-service';
|
||||
import { URI } from 'vscode-uri';
|
||||
export declare function createFormatter(languages: LanguagePlugin<URI>[], services: LanguageServicePlugin[]): {
|
||||
env: import("@volar/language-service").LanguageServiceEnvironment;
|
||||
format: (content: string, languageId: string, options: FormattingOptions) => Promise<string>;
|
||||
settings: {};
|
||||
};
|
||||
37
node_modules/@volar/kit/lib/createFormatter.js
generated
vendored
Normal file
37
node_modules/@volar/kit/lib/createFormatter.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createFormatter = createFormatter;
|
||||
const language_service_1 = require("@volar/language-service");
|
||||
const ts = require("typescript");
|
||||
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const createServiceEnvironment_1 = require("./createServiceEnvironment");
|
||||
function createFormatter(languages, services) {
|
||||
let settings = {};
|
||||
const fakeUri = vscode_uri_1.URI.parse('file:///dummy.txt');
|
||||
const env = (0, createServiceEnvironment_1.createServiceEnvironment)(() => settings);
|
||||
const language = (0, language_service_1.createLanguage)(languages, (0, language_service_1.createUriMap)(false), () => { });
|
||||
const languageService = (0, language_service_1.createLanguageService)(language, services, env, {});
|
||||
return {
|
||||
env,
|
||||
format,
|
||||
get settings() {
|
||||
return settings;
|
||||
},
|
||||
set settings(v) {
|
||||
settings = v;
|
||||
},
|
||||
};
|
||||
async function format(content, languageId, options) {
|
||||
const snapshot = ts.ScriptSnapshot.fromString(content);
|
||||
language.scripts.set(fakeUri, snapshot, languageId);
|
||||
const document = languageService.context.documents.get(fakeUri, languageId, snapshot);
|
||||
const edits = await languageService.getDocumentFormattingEdits(fakeUri, options, undefined, undefined);
|
||||
if (edits?.length) {
|
||||
const newString = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
||||
return newString;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=createFormatter.js.map
|
||||
2
node_modules/@volar/kit/lib/createServiceEnvironment.d.ts
generated
vendored
Normal file
2
node_modules/@volar/kit/lib/createServiceEnvironment.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { LanguageServiceEnvironment } from '@volar/language-service';
|
||||
export declare function createServiceEnvironment(getSettings: () => any): LanguageServiceEnvironment;
|
||||
88
node_modules/@volar/kit/lib/createServiceEnvironment.js
generated
vendored
Normal file
88
node_modules/@volar/kit/lib/createServiceEnvironment.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createServiceEnvironment = createServiceEnvironment;
|
||||
const language_service_1 = require("@volar/language-service");
|
||||
const fs = require("fs");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
function createServiceEnvironment(getSettings) {
|
||||
return {
|
||||
workspaceFolders: [vscode_uri_1.URI.file(process.cwd())],
|
||||
getConfiguration(section) {
|
||||
const settings = getSettings();
|
||||
if (section in settings) {
|
||||
return settings[section];
|
||||
}
|
||||
let result;
|
||||
for (const settingKey in settings) {
|
||||
if (settingKey.startsWith(`${section}.`)) {
|
||||
const value = settings[settingKey];
|
||||
const props = settingKey.substring(section.length + 1).split('.');
|
||||
result ??= {};
|
||||
let current = result;
|
||||
while (props.length > 1) {
|
||||
const prop = props.shift();
|
||||
if (typeof current[prop] !== 'object') {
|
||||
current[prop] = {};
|
||||
}
|
||||
current = current[prop];
|
||||
}
|
||||
current[props.shift()] = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
fs: nodeFs,
|
||||
console,
|
||||
};
|
||||
}
|
||||
const nodeFs = {
|
||||
stat(uri) {
|
||||
if (uri.scheme === 'file') {
|
||||
try {
|
||||
const stats = fs.statSync(uri.fsPath, { throwIfNoEntry: false });
|
||||
if (stats) {
|
||||
return {
|
||||
type: stats.isFile() ? language_service_1.FileType.File
|
||||
: stats.isDirectory() ? language_service_1.FileType.Directory
|
||||
: stats.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
|
||||
: language_service_1.FileType.Unknown,
|
||||
ctime: stats.ctimeMs,
|
||||
mtime: stats.mtimeMs,
|
||||
size: stats.size,
|
||||
};
|
||||
}
|
||||
}
|
||||
catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
},
|
||||
readFile(uri, encoding) {
|
||||
if (uri.scheme === 'file') {
|
||||
try {
|
||||
return fs.readFileSync(uri.fsPath, { encoding: encoding ?? 'utf-8' });
|
||||
}
|
||||
catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
},
|
||||
readDirectory(uri) {
|
||||
if (uri.scheme === 'file') {
|
||||
try {
|
||||
const files = fs.readdirSync(uri.fsPath, { withFileTypes: true });
|
||||
return files.map(file => {
|
||||
return [file.name, file.isFile() ? language_service_1.FileType.File
|
||||
: file.isDirectory() ? language_service_1.FileType.Directory
|
||||
: file.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
|
||||
: language_service_1.FileType.Unknown];
|
||||
});
|
||||
}
|
||||
catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=createServiceEnvironment.js.map
|
||||
7
node_modules/@volar/kit/lib/utils.d.ts
generated
vendored
Normal file
7
node_modules/@volar/kit/lib/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import type * as path from 'typesafe-path/posix';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type * as ts from 'typescript';
|
||||
export declare const defaultCompilerOptions: ts.CompilerOptions;
|
||||
export declare function asPosix(path: string): path.PosixPath;
|
||||
export declare const asFileName: (uri: URI) => string;
|
||||
export declare const asUri: (fileName: string) => URI;
|
||||
20
node_modules/@volar/kit/lib/utils.js
generated
vendored
Normal file
20
node_modules/@volar/kit/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.asUri = exports.asFileName = exports.defaultCompilerOptions = void 0;
|
||||
exports.asPosix = asPosix;
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
exports.defaultCompilerOptions = {
|
||||
allowJs: true,
|
||||
allowSyntheticDefaultImports: true,
|
||||
allowNonTsExtensions: true,
|
||||
resolveJsonModule: true,
|
||||
jsx: 1,
|
||||
};
|
||||
function asPosix(path) {
|
||||
return path.replace(/\\/g, '/');
|
||||
}
|
||||
const asFileName = (uri) => uri.fsPath.replace(/\\/g, '/');
|
||||
exports.asFileName = asFileName;
|
||||
const asUri = (fileName) => vscode_uri_1.URI.file(fileName);
|
||||
exports.asUri = asUri;
|
||||
//# sourceMappingURL=utils.js.map
|
||||
28
node_modules/@volar/kit/package.json
generated
vendored
Normal file
28
node_modules/@volar/kit/package.json
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "@volar/kit",
|
||||
"version": "2.4.12",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"**/*.js",
|
||||
"**/*.d.ts"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/volarjs/volar.js.git",
|
||||
"directory": "packages/kit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@volar/language-service": "2.4.12",
|
||||
"@volar/typescript": "2.4.12",
|
||||
"typesafe-path": "^0.2.2",
|
||||
"vscode-languageserver-textdocument": "^1.0.11",
|
||||
"vscode-uri": "^3.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "*"
|
||||
},
|
||||
"gitHead": "17b9b8a1f522afd1aad1e598d2fd935680d8a8d7"
|
||||
}
|
||||
21
node_modules/@volar/language-core/LICENSE
generated
vendored
Normal file
21
node_modules/@volar/language-core/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-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.
|
||||
9
node_modules/@volar/language-core/index.d.ts
generated
vendored
Normal file
9
node_modules/@volar/language-core/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export { Mapping, SourceMap } from '@volar/source-map';
|
||||
export * from './lib/editorFeatures';
|
||||
export * from './lib/linkedCodeMap';
|
||||
export * from './lib/types';
|
||||
export * from './lib/utils';
|
||||
import type { Language, LanguagePlugin, MapperFactory, SourceScript, VirtualCode } from './lib/types';
|
||||
export declare const defaultMapperFactory: MapperFactory;
|
||||
export declare function createLanguage<T>(plugins: LanguagePlugin<T>[], scriptRegistry: Map<T, SourceScript<T>>, sync: (id: T, includeFsFiles: boolean, shouldRegister: boolean) => void, onAssociationDirty?: (targetId: T) => void): Language<T>;
|
||||
export declare function forEachEmbeddedCode(virtualCode: VirtualCode): Generator<VirtualCode>;
|
||||
239
node_modules/@volar/language-core/index.js
generated
vendored
Normal file
239
node_modules/@volar/language-core/index.js
generated
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defaultMapperFactory = exports.SourceMap = void 0;
|
||||
exports.createLanguage = createLanguage;
|
||||
exports.forEachEmbeddedCode = forEachEmbeddedCode;
|
||||
var source_map_1 = require("@volar/source-map");
|
||||
Object.defineProperty(exports, "SourceMap", { enumerable: true, get: function () { return source_map_1.SourceMap; } });
|
||||
__exportStar(require("./lib/editorFeatures"), exports);
|
||||
__exportStar(require("./lib/linkedCodeMap"), exports);
|
||||
__exportStar(require("./lib/types"), exports);
|
||||
__exportStar(require("./lib/utils"), exports);
|
||||
const source_map_2 = require("@volar/source-map");
|
||||
const linkedCodeMap_1 = require("./lib/linkedCodeMap");
|
||||
const defaultMapperFactory = mappings => new source_map_2.SourceMap(mappings);
|
||||
exports.defaultMapperFactory = defaultMapperFactory;
|
||||
function createLanguage(plugins, scriptRegistry, sync, onAssociationDirty) {
|
||||
const virtualCodeToSourceScriptMap = new WeakMap();
|
||||
const virtualCodeToSourceMap = new WeakMap();
|
||||
const virtualCodeToLinkedCodeMap = new WeakMap();
|
||||
const language = {
|
||||
mapperFactory: exports.defaultMapperFactory,
|
||||
plugins,
|
||||
scripts: {
|
||||
fromVirtualCode(virtualCode) {
|
||||
return virtualCodeToSourceScriptMap.get(virtualCode);
|
||||
},
|
||||
get(id, includeFsFiles = true, shouldRegister = false) {
|
||||
sync(id, includeFsFiles, shouldRegister);
|
||||
const result = scriptRegistry.get(id);
|
||||
// The sync function provider may not always call the set function due to caching, so it is necessary to explicitly check isAssociationDirty.
|
||||
if (result?.isAssociationDirty) {
|
||||
this.set(id, result.snapshot, result.languageId);
|
||||
}
|
||||
return scriptRegistry.get(id);
|
||||
},
|
||||
set(id, snapshot, languageId, _plugins = plugins) {
|
||||
if (!languageId) {
|
||||
for (const plugin of plugins) {
|
||||
languageId = plugin.getLanguageId?.(id);
|
||||
if (languageId) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!languageId) {
|
||||
console.warn(`languageId not found for ${id}`);
|
||||
return;
|
||||
}
|
||||
let associatedOnly = false;
|
||||
for (const plugin of plugins) {
|
||||
if (plugin.isAssociatedFileOnly?.(id, languageId)) {
|
||||
associatedOnly = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (scriptRegistry.has(id)) {
|
||||
const sourceScript = scriptRegistry.get(id);
|
||||
if (sourceScript.languageId !== languageId || sourceScript.associatedOnly !== associatedOnly) {
|
||||
this.delete(id);
|
||||
triggerTargetsDirty(sourceScript);
|
||||
return this.set(id, snapshot, languageId);
|
||||
}
|
||||
else if (associatedOnly) {
|
||||
if (sourceScript.snapshot !== snapshot) {
|
||||
sourceScript.snapshot = snapshot;
|
||||
triggerTargetsDirty(sourceScript);
|
||||
}
|
||||
}
|
||||
else if (sourceScript.isAssociationDirty || sourceScript.snapshot !== snapshot) {
|
||||
if (sourceScript.snapshot !== snapshot) {
|
||||
sourceScript.snapshot = snapshot;
|
||||
triggerTargetsDirty(sourceScript);
|
||||
}
|
||||
const codegenCtx = prepareCreateVirtualCode(sourceScript);
|
||||
if (sourceScript.generated) {
|
||||
const { updateVirtualCode, createVirtualCode } = sourceScript.generated.languagePlugin;
|
||||
const newVirtualCode = updateVirtualCode
|
||||
? updateVirtualCode(id, sourceScript.generated.root, snapshot, codegenCtx)
|
||||
: createVirtualCode?.(id, languageId, snapshot, codegenCtx);
|
||||
if (newVirtualCode) {
|
||||
sourceScript.generated.root = newVirtualCode;
|
||||
sourceScript.generated.embeddedCodes.clear();
|
||||
for (const code of forEachEmbeddedCode(sourceScript.generated.root)) {
|
||||
virtualCodeToSourceScriptMap.set(code, sourceScript);
|
||||
sourceScript.generated.embeddedCodes.set(code.id, code);
|
||||
}
|
||||
return sourceScript;
|
||||
}
|
||||
else {
|
||||
this.delete(id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// not changed
|
||||
return sourceScript;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// created
|
||||
const sourceScript = {
|
||||
id: id,
|
||||
languageId,
|
||||
snapshot,
|
||||
associatedIds: new Set(),
|
||||
targetIds: new Set(),
|
||||
associatedOnly
|
||||
};
|
||||
scriptRegistry.set(id, sourceScript);
|
||||
if (associatedOnly) {
|
||||
return sourceScript;
|
||||
}
|
||||
for (const languagePlugin of _plugins) {
|
||||
const virtualCode = languagePlugin.createVirtualCode?.(id, languageId, snapshot, prepareCreateVirtualCode(sourceScript));
|
||||
if (virtualCode) {
|
||||
sourceScript.generated = {
|
||||
root: virtualCode,
|
||||
languagePlugin,
|
||||
embeddedCodes: new Map(),
|
||||
};
|
||||
for (const code of forEachEmbeddedCode(virtualCode)) {
|
||||
virtualCodeToSourceScriptMap.set(code, sourceScript);
|
||||
sourceScript.generated.embeddedCodes.set(code.id, code);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sourceScript;
|
||||
}
|
||||
},
|
||||
delete(id) {
|
||||
const sourceScript = scriptRegistry.get(id);
|
||||
if (sourceScript) {
|
||||
sourceScript.generated?.languagePlugin.disposeVirtualCode?.(id, sourceScript.generated.root);
|
||||
scriptRegistry.delete(id);
|
||||
triggerTargetsDirty(sourceScript);
|
||||
}
|
||||
},
|
||||
},
|
||||
maps: {
|
||||
get(virtualCode, sourceScript) {
|
||||
let mapCache = virtualCodeToSourceMap.get(virtualCode.snapshot);
|
||||
if (!mapCache) {
|
||||
virtualCodeToSourceMap.set(virtualCode.snapshot, mapCache = new WeakMap());
|
||||
}
|
||||
if (!mapCache.has(sourceScript.snapshot)) {
|
||||
const mappings = virtualCode.associatedScriptMappings?.get(sourceScript.id) ?? virtualCode.mappings;
|
||||
mapCache.set(sourceScript.snapshot, language.mapperFactory(mappings));
|
||||
}
|
||||
return mapCache.get(sourceScript.snapshot);
|
||||
},
|
||||
*forEach(virtualCode) {
|
||||
const sourceScript = virtualCodeToSourceScriptMap.get(virtualCode);
|
||||
yield [
|
||||
sourceScript,
|
||||
this.get(virtualCode, sourceScript),
|
||||
];
|
||||
if (virtualCode.associatedScriptMappings) {
|
||||
for (const [relatedScriptId] of virtualCode.associatedScriptMappings) {
|
||||
const relatedSourceScript = scriptRegistry.get(relatedScriptId);
|
||||
if (relatedSourceScript) {
|
||||
yield [
|
||||
relatedSourceScript,
|
||||
this.get(virtualCode, relatedSourceScript),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
linkedCodeMaps: {
|
||||
get(virtualCode) {
|
||||
const sourceScript = virtualCodeToSourceScriptMap.get(virtualCode);
|
||||
let mapCache = virtualCodeToLinkedCodeMap.get(virtualCode.snapshot);
|
||||
if (mapCache?.[0] !== sourceScript.snapshot) {
|
||||
virtualCodeToLinkedCodeMap.set(virtualCode.snapshot, mapCache = [
|
||||
sourceScript.snapshot,
|
||||
virtualCode.linkedCodeMappings
|
||||
? new linkedCodeMap_1.LinkedCodeMap(virtualCode.linkedCodeMappings)
|
||||
: undefined,
|
||||
]);
|
||||
}
|
||||
return mapCache[1];
|
||||
},
|
||||
},
|
||||
};
|
||||
return language;
|
||||
function triggerTargetsDirty(sourceScript) {
|
||||
sourceScript.targetIds.forEach(id => {
|
||||
const sourceScript = scriptRegistry.get(id);
|
||||
if (sourceScript) {
|
||||
sourceScript.isAssociationDirty = true;
|
||||
onAssociationDirty?.(sourceScript.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
function prepareCreateVirtualCode(sourceScript) {
|
||||
for (const id of sourceScript.associatedIds) {
|
||||
scriptRegistry.get(id)?.targetIds.delete(sourceScript.id);
|
||||
}
|
||||
sourceScript.associatedIds.clear();
|
||||
sourceScript.isAssociationDirty = false;
|
||||
return {
|
||||
getAssociatedScript(id) {
|
||||
sync(id, true, true);
|
||||
const relatedSourceScript = scriptRegistry.get(id);
|
||||
if (relatedSourceScript) {
|
||||
relatedSourceScript.targetIds.add(sourceScript.id);
|
||||
sourceScript.associatedIds.add(relatedSourceScript.id);
|
||||
}
|
||||
return relatedSourceScript;
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
function* forEachEmbeddedCode(virtualCode) {
|
||||
yield virtualCode;
|
||||
if (virtualCode.embeddedCodes) {
|
||||
for (const embeddedCode of virtualCode.embeddedCodes) {
|
||||
yield* forEachEmbeddedCode(embeddedCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=index.js.map
|
||||
30
node_modules/@volar/language-core/lib/editorFeatures.d.ts
generated
vendored
Normal file
30
node_modules/@volar/language-core/lib/editorFeatures.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { CodeInformation } from './types';
|
||||
export declare function isHoverEnabled(info: CodeInformation): boolean;
|
||||
export declare function isInlayHintsEnabled(info: CodeInformation): boolean;
|
||||
export declare function isCodeLensEnabled(info: CodeInformation): boolean;
|
||||
export declare function isMonikerEnabled(info: CodeInformation): boolean;
|
||||
export declare function isInlineValueEnabled(info: CodeInformation): boolean;
|
||||
export declare function isSemanticTokensEnabled(info: CodeInformation): boolean;
|
||||
export declare function isCallHierarchyEnabled(info: CodeInformation): boolean;
|
||||
export declare function isTypeHierarchyEnabled(info: CodeInformation): boolean;
|
||||
export declare function isRenameEnabled(info: CodeInformation): boolean;
|
||||
export declare function isDefinitionEnabled(info: CodeInformation): boolean;
|
||||
export declare function isTypeDefinitionEnabled(info: CodeInformation): boolean;
|
||||
export declare function isReferencesEnabled(info: CodeInformation): boolean;
|
||||
export declare function isImplementationEnabled(info: CodeInformation): boolean;
|
||||
export declare function isHighlightEnabled(info: CodeInformation): boolean;
|
||||
export declare function isSymbolsEnabled(info: CodeInformation): boolean;
|
||||
export declare function isFoldingRangesEnabled(info: CodeInformation): boolean;
|
||||
export declare function isSelectionRangesEnabled(info: CodeInformation): boolean;
|
||||
export declare function isLinkedEditingEnabled(info: CodeInformation): boolean;
|
||||
export declare function isColorEnabled(info: CodeInformation): boolean;
|
||||
export declare function isDocumentLinkEnabled(info: CodeInformation): boolean;
|
||||
export declare function isDiagnosticsEnabled(info: CodeInformation): boolean;
|
||||
export declare function isCodeActionsEnabled(info: CodeInformation): boolean;
|
||||
export declare function isFormattingEnabled(info: CodeInformation): boolean;
|
||||
export declare function isCompletionEnabled(info: CodeInformation): boolean;
|
||||
export declare function isAutoInsertEnabled(info: CodeInformation): boolean;
|
||||
export declare function isSignatureHelpEnabled(info: CodeInformation): boolean;
|
||||
export declare function shouldReportDiagnostics(info: CodeInformation, source: string | undefined, code: string | number | undefined): boolean;
|
||||
export declare function resolveRenameNewName(newName: string, info: CodeInformation): string;
|
||||
export declare function resolveRenameEditText(text: string, info: CodeInformation): string;
|
||||
131
node_modules/@volar/language-core/lib/editorFeatures.js
generated
vendored
Normal file
131
node_modules/@volar/language-core/lib/editorFeatures.js
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isHoverEnabled = isHoverEnabled;
|
||||
exports.isInlayHintsEnabled = isInlayHintsEnabled;
|
||||
exports.isCodeLensEnabled = isCodeLensEnabled;
|
||||
exports.isMonikerEnabled = isMonikerEnabled;
|
||||
exports.isInlineValueEnabled = isInlineValueEnabled;
|
||||
exports.isSemanticTokensEnabled = isSemanticTokensEnabled;
|
||||
exports.isCallHierarchyEnabled = isCallHierarchyEnabled;
|
||||
exports.isTypeHierarchyEnabled = isTypeHierarchyEnabled;
|
||||
exports.isRenameEnabled = isRenameEnabled;
|
||||
exports.isDefinitionEnabled = isDefinitionEnabled;
|
||||
exports.isTypeDefinitionEnabled = isTypeDefinitionEnabled;
|
||||
exports.isReferencesEnabled = isReferencesEnabled;
|
||||
exports.isImplementationEnabled = isImplementationEnabled;
|
||||
exports.isHighlightEnabled = isHighlightEnabled;
|
||||
exports.isSymbolsEnabled = isSymbolsEnabled;
|
||||
exports.isFoldingRangesEnabled = isFoldingRangesEnabled;
|
||||
exports.isSelectionRangesEnabled = isSelectionRangesEnabled;
|
||||
exports.isLinkedEditingEnabled = isLinkedEditingEnabled;
|
||||
exports.isColorEnabled = isColorEnabled;
|
||||
exports.isDocumentLinkEnabled = isDocumentLinkEnabled;
|
||||
exports.isDiagnosticsEnabled = isDiagnosticsEnabled;
|
||||
exports.isCodeActionsEnabled = isCodeActionsEnabled;
|
||||
exports.isFormattingEnabled = isFormattingEnabled;
|
||||
exports.isCompletionEnabled = isCompletionEnabled;
|
||||
exports.isAutoInsertEnabled = isAutoInsertEnabled;
|
||||
exports.isSignatureHelpEnabled = isSignatureHelpEnabled;
|
||||
exports.shouldReportDiagnostics = shouldReportDiagnostics;
|
||||
exports.resolveRenameNewName = resolveRenameNewName;
|
||||
exports.resolveRenameEditText = resolveRenameEditText;
|
||||
function isHoverEnabled(info) {
|
||||
return !!info.semantic;
|
||||
}
|
||||
function isInlayHintsEnabled(info) {
|
||||
return !!info.semantic;
|
||||
}
|
||||
function isCodeLensEnabled(info) {
|
||||
return !!info.semantic;
|
||||
}
|
||||
function isMonikerEnabled(info) {
|
||||
return !!info.semantic;
|
||||
}
|
||||
function isInlineValueEnabled(info) {
|
||||
return !!info.semantic;
|
||||
}
|
||||
function isSemanticTokensEnabled(info) {
|
||||
return typeof info.semantic === 'object'
|
||||
? info.semantic.shouldHighlight?.() ?? true
|
||||
: !!info.semantic;
|
||||
}
|
||||
function isCallHierarchyEnabled(info) {
|
||||
return !!info.navigation;
|
||||
}
|
||||
function isTypeHierarchyEnabled(info) {
|
||||
return !!info.navigation;
|
||||
}
|
||||
function isRenameEnabled(info) {
|
||||
return typeof info.navigation === 'object'
|
||||
? info.navigation.shouldRename?.() ?? true
|
||||
: !!info.navigation;
|
||||
}
|
||||
function isDefinitionEnabled(info) {
|
||||
return !!info.navigation;
|
||||
}
|
||||
function isTypeDefinitionEnabled(info) {
|
||||
return !!info.navigation;
|
||||
}
|
||||
function isReferencesEnabled(info) {
|
||||
return !!info.navigation;
|
||||
}
|
||||
function isImplementationEnabled(info) {
|
||||
return !!info.navigation;
|
||||
}
|
||||
function isHighlightEnabled(info) {
|
||||
return !!info.navigation;
|
||||
}
|
||||
function isSymbolsEnabled(info) {
|
||||
return !!info.structure;
|
||||
}
|
||||
function isFoldingRangesEnabled(info) {
|
||||
return !!info.structure;
|
||||
}
|
||||
function isSelectionRangesEnabled(info) {
|
||||
return !!info.structure;
|
||||
}
|
||||
function isLinkedEditingEnabled(info) {
|
||||
return !!info.structure;
|
||||
}
|
||||
function isColorEnabled(info) {
|
||||
return !!info.structure;
|
||||
}
|
||||
function isDocumentLinkEnabled(info) {
|
||||
return !!info.structure;
|
||||
}
|
||||
function isDiagnosticsEnabled(info) {
|
||||
return !!info.verification;
|
||||
}
|
||||
function isCodeActionsEnabled(info) {
|
||||
return !!info.verification;
|
||||
}
|
||||
function isFormattingEnabled(info) {
|
||||
return !!info.format;
|
||||
}
|
||||
function isCompletionEnabled(info) {
|
||||
return !!info.completion;
|
||||
}
|
||||
function isAutoInsertEnabled(info) {
|
||||
return !!info.completion;
|
||||
}
|
||||
function isSignatureHelpEnabled(info) {
|
||||
return !!info.completion;
|
||||
}
|
||||
// should...
|
||||
function shouldReportDiagnostics(info, source, code) {
|
||||
return typeof info.verification === 'object'
|
||||
? info.verification.shouldReport?.(source, code) ?? true
|
||||
: !!info.verification;
|
||||
}
|
||||
// resolve...
|
||||
function resolveRenameNewName(newName, info) {
|
||||
return typeof info.navigation === 'object'
|
||||
? info.navigation.resolveRenameNewName?.(newName) ?? newName
|
||||
: newName;
|
||||
}
|
||||
function resolveRenameEditText(text, info) {
|
||||
return typeof info.navigation === 'object'
|
||||
? info.navigation.resolveRenameEditText?.(text) ?? text
|
||||
: text;
|
||||
}
|
||||
//# sourceMappingURL=editorFeatures.js.map
|
||||
4
node_modules/@volar/language-core/lib/linkedCodeMap.d.ts
generated
vendored
Normal file
4
node_modules/@volar/language-core/lib/linkedCodeMap.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { SourceMap } from '@volar/source-map';
|
||||
export declare class LinkedCodeMap extends SourceMap<any> {
|
||||
getLinkedOffsets(start: number): Generator<number, void, unknown>;
|
||||
}
|
||||
16
node_modules/@volar/language-core/lib/linkedCodeMap.js
generated
vendored
Normal file
16
node_modules/@volar/language-core/lib/linkedCodeMap.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LinkedCodeMap = void 0;
|
||||
const source_map_1 = require("@volar/source-map");
|
||||
class LinkedCodeMap extends source_map_1.SourceMap {
|
||||
*getLinkedOffsets(start) {
|
||||
for (const mapped of this.toGeneratedLocation(start)) {
|
||||
yield mapped[0];
|
||||
}
|
||||
for (const mapped of this.toSourceLocation(start)) {
|
||||
yield mapped[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.LinkedCodeMap = LinkedCodeMap;
|
||||
//# sourceMappingURL=linkedCodeMap.js.map
|
||||
155
node_modules/@volar/language-core/lib/types.d.ts
generated
vendored
Normal file
155
node_modules/@volar/language-core/lib/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
import type { Mapping } from '@volar/source-map';
|
||||
import type { LinkedCodeMap } from './linkedCodeMap';
|
||||
export interface Mapper {
|
||||
mappings: Mapping<CodeInformation>[];
|
||||
toSourceRange(start: number, end: number, fallbackToAnyMatch: boolean, filter?: (data: CodeInformation) => boolean): Generator<readonly [number, number, Mapping<CodeInformation>, Mapping<CodeInformation>]>;
|
||||
toGeneratedRange(start: number, end: number, fallbackToAnyMatch: boolean, filter?: (data: CodeInformation) => boolean): Generator<readonly [number, number, Mapping<CodeInformation>, Mapping<CodeInformation>]>;
|
||||
toSourceLocation(generatedOffset: number, filter?: (data: CodeInformation) => boolean): Generator<readonly [number, Mapping<CodeInformation>]>;
|
||||
toGeneratedLocation(sourceOffset: number, filter?: (data: CodeInformation) => boolean): Generator<readonly [number, Mapping<CodeInformation>]>;
|
||||
}
|
||||
export type MapperFactory = (mappings: Mapping<CodeInformation>[]) => Mapper;
|
||||
export interface Language<T = unknown> {
|
||||
mapperFactory: MapperFactory;
|
||||
plugins: LanguagePlugin<T>[];
|
||||
scripts: {
|
||||
get(id: T, includeFsFiles?: boolean, shouldRegister?: boolean): SourceScript<T> | undefined;
|
||||
set(id: T, snapshot: IScriptSnapshot, languageId?: string, plugins?: LanguagePlugin<T>[]): SourceScript<T> | undefined;
|
||||
delete(id: T): void;
|
||||
fromVirtualCode(virtualCode: VirtualCode): SourceScript<T>;
|
||||
};
|
||||
maps: {
|
||||
get(virtualCode: VirtualCode, sourceScript: SourceScript<T>): Mapper;
|
||||
forEach(virtualCode: VirtualCode): Generator<[sourceScript: SourceScript<T>, map: Mapper]>;
|
||||
};
|
||||
linkedCodeMaps: {
|
||||
get(virtualCode: VirtualCode): LinkedCodeMap | undefined;
|
||||
};
|
||||
}
|
||||
export interface SourceScript<T = unknown> {
|
||||
id: T;
|
||||
languageId: string;
|
||||
snapshot: IScriptSnapshot;
|
||||
targetIds: Set<T>;
|
||||
associatedIds: Set<T>;
|
||||
associatedOnly: boolean;
|
||||
isAssociationDirty?: boolean;
|
||||
generated?: {
|
||||
root: VirtualCode;
|
||||
languagePlugin: LanguagePlugin<T>;
|
||||
embeddedCodes: Map<string, VirtualCode>;
|
||||
};
|
||||
}
|
||||
export type CodeMapping = Mapping<CodeInformation>;
|
||||
export interface VirtualCode {
|
||||
id: string;
|
||||
languageId: string;
|
||||
snapshot: IScriptSnapshot;
|
||||
mappings: CodeMapping[];
|
||||
associatedScriptMappings?: Map<unknown, CodeMapping[]>;
|
||||
embeddedCodes?: VirtualCode[];
|
||||
linkedCodeMappings?: Mapping[];
|
||||
}
|
||||
/**
|
||||
* CodeInformation is a configuration object attached to each CodeMapping (between source code and generated code,
|
||||
* e.g. between the template code in a .vue file and the type-checkable TS code generated from it) that
|
||||
* determines what code/language features are expected to be available for the mapping.
|
||||
*
|
||||
* Due to the dynamic nature of code generation and the fact that, for example, things like Code Actions
|
||||
* and auto-complete shouldn't be triggerable on certain "in-between" regions of generated code, we need
|
||||
* a way to shut off certain features in certain regions, while leaving them enabled in others.
|
||||
*/
|
||||
export interface CodeInformation {
|
||||
/** virtual code is expected to support verification, where verification includes:
|
||||
*
|
||||
* - diagnostics (syntactic, semantic, and others, such as those generated by the TypeScript language service on generated TS code)
|
||||
* - code actions (refactorings, quick fixes,etc.)
|
||||
*/
|
||||
verification?: boolean | {
|
||||
/**
|
||||
* when present, `shouldReport` callback is invoked to determine whether a diagnostic
|
||||
* raised in the generated code should be propagated back to the original source code.
|
||||
* Note that when this callback is present, diagnostic processing (e.g. typechecking) will
|
||||
* still be performed, but the results will not be reported back to the original source code. */
|
||||
shouldReport?(source: string | undefined, code: string | number | undefined): boolean;
|
||||
};
|
||||
/** virtual code is expected to support assisted completion */
|
||||
completion?: boolean | {
|
||||
isAdditional?: boolean;
|
||||
onlyImport?: boolean;
|
||||
};
|
||||
/** virtual code is expected correctly reflect semantic of the source code. Specifically this controls the following langauge features:
|
||||
*
|
||||
* - hover
|
||||
* - inlay hints
|
||||
* - code lens
|
||||
* - semantic tokens
|
||||
* - others
|
||||
*
|
||||
* Note that semantic diagnostics (e.g. TS type-checking) are covered by the `verification` property above.
|
||||
*/
|
||||
semantic?: boolean | {
|
||||
shouldHighlight?(): boolean;
|
||||
};
|
||||
/** virtual code is expected correctly reflect reference relationships of the source code */
|
||||
navigation?: boolean | {
|
||||
shouldRename?(): boolean;
|
||||
resolveRenameNewName?(newName: string): string;
|
||||
resolveRenameEditText?(newText: string): string;
|
||||
};
|
||||
/** virtual code is expected correctly reflect the structural information of the source code */
|
||||
structure?: boolean;
|
||||
/** virtual code is expected correctly reflect the format information of the source code */
|
||||
format?: boolean;
|
||||
}
|
||||
export interface LanguagePlugin<T = unknown, K extends VirtualCode = VirtualCode> {
|
||||
/**
|
||||
* For files that are not opened in the IDE, the language ID will not be synchronized to the language server, so a hook is needed to parse the language ID of files that are known extension but not opened in the IDE.
|
||||
*/
|
||||
getLanguageId(scriptId: T): string | undefined;
|
||||
/**
|
||||
* Generate a virtual code.
|
||||
*/
|
||||
createVirtualCode?(scriptId: T, languageId: string, snapshot: IScriptSnapshot, ctx: CodegenContext<T>): K | undefined;
|
||||
/**
|
||||
* Incremental update a virtual code. If not provide, call createVirtualCode again.
|
||||
*/
|
||||
updateVirtualCode?(scriptId: T, virtualCode: K, newSnapshot: IScriptSnapshot, ctx: CodegenContext<T>): K | undefined;
|
||||
/**
|
||||
* Cleanup a virtual code.
|
||||
*/
|
||||
disposeVirtualCode?(scriptId: T, virtualCode: K): void;
|
||||
/**
|
||||
* Some file types should not be parsed or processed as TypeScript files,
|
||||
* as they are used only as sources for generated files.
|
||||
*
|
||||
* This functionality is required only in TS plugin mode.
|
||||
*/
|
||||
isAssociatedFileOnly?(scriptId: T, languageId: string): boolean;
|
||||
}
|
||||
export interface CodegenContext<T = unknown> {
|
||||
getAssociatedScript(scriptId: T): SourceScript<T> | undefined;
|
||||
}
|
||||
export interface IScriptSnapshot {
|
||||
/** Gets a portion of the script snapshot specified by [start, end). */
|
||||
getText(start: number, end: number): string;
|
||||
/** Gets the length of this script snapshot. */
|
||||
getLength(): number;
|
||||
/**
|
||||
* Gets the TextChangeRange that describe how the text changed between this text and
|
||||
* an older version. This information is used by the incremental parser to determine
|
||||
* what sections of the script need to be re-parsed. 'undefined' can be returned if the
|
||||
* change range cannot be determined. However, in that case, incremental parsing will
|
||||
* not happen and the entire document will be re - parsed.
|
||||
*/
|
||||
getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined;
|
||||
/** Releases all resources held by this script snapshot */
|
||||
dispose?(): void;
|
||||
}
|
||||
export interface TextChangeRange {
|
||||
span: TextSpan;
|
||||
newLength: number;
|
||||
}
|
||||
export interface TextSpan {
|
||||
start: number;
|
||||
length: number;
|
||||
}
|
||||
3
node_modules/@volar/language-core/lib/types.js
generated
vendored
Normal file
3
node_modules/@volar/language-core/lib/types.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=types.js.map
|
||||
12
node_modules/@volar/language-core/lib/utils.d.ts
generated
vendored
Normal file
12
node_modules/@volar/language-core/lib/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
export declare class FileMap<T> extends Map<string, T> {
|
||||
private caseSensitive;
|
||||
private originalFileNames;
|
||||
constructor(caseSensitive: boolean);
|
||||
keys(): MapIterator<string>;
|
||||
get(key: string): T | undefined;
|
||||
has(key: string): boolean;
|
||||
set(key: string, value: T): this;
|
||||
delete(key: string): boolean;
|
||||
clear(): void;
|
||||
normalizeId(id: string): string;
|
||||
}
|
||||
36
node_modules/@volar/language-core/lib/utils.js
generated
vendored
Normal file
36
node_modules/@volar/language-core/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FileMap = void 0;
|
||||
class FileMap extends Map {
|
||||
constructor(caseSensitive) {
|
||||
super();
|
||||
this.caseSensitive = caseSensitive;
|
||||
this.originalFileNames = new Map();
|
||||
}
|
||||
keys() {
|
||||
return this.originalFileNames.values();
|
||||
}
|
||||
get(key) {
|
||||
return super.get(this.normalizeId(key));
|
||||
}
|
||||
has(key) {
|
||||
return super.has(this.normalizeId(key));
|
||||
}
|
||||
set(key, value) {
|
||||
this.originalFileNames.set(this.normalizeId(key), key);
|
||||
return super.set(this.normalizeId(key), value);
|
||||
}
|
||||
delete(key) {
|
||||
this.originalFileNames.delete(this.normalizeId(key));
|
||||
return super.delete(this.normalizeId(key));
|
||||
}
|
||||
clear() {
|
||||
this.originalFileNames.clear();
|
||||
return super.clear();
|
||||
}
|
||||
normalizeId(id) {
|
||||
return this.caseSensitive ? id : id.toLowerCase();
|
||||
}
|
||||
}
|
||||
exports.FileMap = FileMap;
|
||||
//# sourceMappingURL=utils.js.map
|
||||
18
node_modules/@volar/language-core/package.json
generated
vendored
Normal file
18
node_modules/@volar/language-core/package.json
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@volar/language-core",
|
||||
"version": "2.4.12",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"**/*.js",
|
||||
"**/*.d.ts"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/volarjs/volar.js.git",
|
||||
"directory": "packages/language-core"
|
||||
},
|
||||
"dependencies": {
|
||||
"@volar/source-map": "2.4.12"
|
||||
},
|
||||
"gitHead": "17b9b8a1f522afd1aad1e598d2fd935680d8a8d7"
|
||||
}
|
||||
21
node_modules/@volar/language-server/LICENSE
generated
vendored
Normal file
21
node_modules/@volar/language-server/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-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.
|
||||
61
node_modules/@volar/language-server/browser.d.ts
generated
vendored
Normal file
61
node_modules/@volar/language-server/browser.d.ts
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
import * as vscode from 'vscode-languageserver/browser';
|
||||
import { URI } from 'vscode-uri';
|
||||
export * from 'vscode-languageserver/browser';
|
||||
export * from './index';
|
||||
export * from './lib/project/simpleProject';
|
||||
export * from './lib/project/typescriptProject';
|
||||
export * from './lib/server';
|
||||
export declare function createConnection(): vscode.Connection;
|
||||
export declare function createServer(connection: vscode.Connection): {
|
||||
initializeParams: vscode.InitializeParams;
|
||||
project: import("./index").LanguageServerProject;
|
||||
languageServicePlugins: import("@volar/language-service/lib/types").LanguageServicePlugin<any>[];
|
||||
initialize(params: vscode.InitializeParams, project: import("./index").LanguageServerProject, languageServicePlugins: import("@volar/language-service/lib/types").LanguageServicePlugin[]): vscode.InitializeResult<import("./index").ExperimentalFeatures>;
|
||||
initialized(): void;
|
||||
shutdown(): void;
|
||||
configurations: {
|
||||
get: <T>(section: string, scopeUri?: string) => Promise<T | undefined>;
|
||||
onDidChange: (cb: vscode.NotificationHandler<vscode.DidChangeConfigurationParams>) => {
|
||||
dispose(): void;
|
||||
};
|
||||
};
|
||||
editorFeatures: void;
|
||||
documents: {
|
||||
all: () => import("./lib/utils/snapshotDocument").SnapshotDocument[];
|
||||
onDidChangeContent: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
|
||||
onDidOpen: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
|
||||
onDidClose: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
|
||||
onDidSave: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
|
||||
get(uri: URI): import("./lib/utils/snapshotDocument").SnapshotDocument | undefined;
|
||||
};
|
||||
workspaceFolders: {
|
||||
readonly all: URI[];
|
||||
has(uri: URI): boolean;
|
||||
onDidChange: (cb: vscode.NotificationHandler<vscode.WorkspaceFoldersChangeEvent>) => {
|
||||
dispose(): void;
|
||||
};
|
||||
};
|
||||
fileWatcher: {
|
||||
watchFiles: (patterns: string[]) => Promise<vscode.Disposable>;
|
||||
onDidChangeWatchedFiles: (cb: vscode.NotificationHandler<vscode.DidChangeWatchedFilesParams>) => {
|
||||
dispose: () => void;
|
||||
};
|
||||
};
|
||||
languageFeatures: {
|
||||
requestRefresh: (clearDiagnostics: boolean) => Promise<void>;
|
||||
};
|
||||
fileSystem: {
|
||||
readFile(uri: URI): string | Thenable<string | undefined>;
|
||||
stat(uri: URI): import("@volar/language-service/lib/types").FileStat | Thenable<import("@volar/language-service/lib/types").FileStat | undefined>;
|
||||
readDirectory(uri: URI): import("@volar/language-service/lib/types").ProviderResult<[string, import("@volar/language-service/lib/types").FileType][]>;
|
||||
install(scheme: string, provider: import("@volar/language-service/lib/types").FileSystem): void;
|
||||
};
|
||||
env: import("./index").LanguageServerEnvironment;
|
||||
connection: vscode.Connection;
|
||||
onInitialize(callback: (serverCapabilities: vscode.ServerCapabilities<import("./index").ExperimentalFeatures>) => void): void;
|
||||
onInitialized(callback: () => void): void;
|
||||
};
|
||||
export declare function loadTsdkByUrl(tsdkUrl: string, locale: string | undefined): Promise<{
|
||||
typescript: typeof import("typescript");
|
||||
diagnosticMessages: import("typescript").MapLike<string> | undefined;
|
||||
}>;
|
||||
79
node_modules/@volar/language-server/browser.js
generated
vendored
Normal file
79
node_modules/@volar/language-server/browser.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createConnection = createConnection;
|
||||
exports.createServer = createServer;
|
||||
exports.loadTsdkByUrl = loadTsdkByUrl;
|
||||
const vscode = require("vscode-languageserver/browser");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const http_1 = require("./lib/fileSystemProviders/http");
|
||||
const server_1 = require("./lib/server");
|
||||
const http_2 = require("./lib/fileSystemProviders/http");
|
||||
__exportStar(require("vscode-languageserver/browser"), exports);
|
||||
__exportStar(require("./index"), exports);
|
||||
__exportStar(require("./lib/project/simpleProject"), exports);
|
||||
__exportStar(require("./lib/project/typescriptProject"), exports);
|
||||
__exportStar(require("./lib/server"), exports);
|
||||
function createConnection() {
|
||||
const messageReader = new vscode.BrowserMessageReader(self);
|
||||
const messageWriter = new vscode.BrowserMessageWriter(self);
|
||||
const connection = vscode.createConnection(messageReader, messageWriter);
|
||||
return connection;
|
||||
}
|
||||
function createServer(connection) {
|
||||
const server = (0, server_1.createServerBase)(connection, {
|
||||
timer: {
|
||||
setImmediate: (callback, ...args) => {
|
||||
setTimeout(callback, 0, ...args);
|
||||
},
|
||||
},
|
||||
});
|
||||
server.fileSystem.install('http', http_2.provider);
|
||||
server.fileSystem.install('https', http_2.provider);
|
||||
server.onInitialized(() => (0, http_2.listenEditorSettings)(server));
|
||||
return server;
|
||||
}
|
||||
async function loadTsdkByUrl(tsdkUrl, locale) {
|
||||
locale = locale?.toLowerCase();
|
||||
return {
|
||||
typescript: await loadLib(),
|
||||
diagnosticMessages: await loadLocalizedDiagnosticMessages(),
|
||||
};
|
||||
async function loadLib() {
|
||||
const originalModule = globalThis.module;
|
||||
try {
|
||||
globalThis.module = { exports: {} };
|
||||
await import(`${tsdkUrl}/typescript.js`);
|
||||
return globalThis.module.exports;
|
||||
}
|
||||
finally {
|
||||
globalThis.module = originalModule;
|
||||
}
|
||||
}
|
||||
async function loadLocalizedDiagnosticMessages() {
|
||||
if (locale === 'en') {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const json = await (0, http_1.handler)(vscode_uri_1.URI.parse(`${tsdkUrl}/${locale}/diagnosticMessages.generated.json`));
|
||||
if (json) {
|
||||
return JSON.parse(json);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=browser.js.map
|
||||
5
node_modules/@volar/language-server/index.d.ts
generated
vendored
Normal file
5
node_modules/@volar/language-server/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from './protocol';
|
||||
export * from './lib/types';
|
||||
export * from 'vscode-languageserver';
|
||||
export * from '@volar/language-core/lib/types';
|
||||
export * from '@volar/language-service/lib/types';
|
||||
23
node_modules/@volar/language-server/index.js
generated
vendored
Normal file
23
node_modules/@volar/language-server/index.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
__exportStar(require("./protocol"), exports);
|
||||
__exportStar(require("./lib/types"), exports);
|
||||
// only export types of depend packages
|
||||
__exportStar(require("vscode-languageserver"), exports);
|
||||
__exportStar(require("@volar/language-core/lib/types"), exports);
|
||||
__exportStar(require("@volar/language-service/lib/types"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
8
node_modules/@volar/language-server/lib/features/configurations.d.ts
generated
vendored
Normal file
8
node_modules/@volar/language-server/lib/features/configurations.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import * as vscode from 'vscode-languageserver';
|
||||
import { LanguageServerState } from '../types';
|
||||
export declare function register(server: LanguageServerState): {
|
||||
get: <T>(section: string, scopeUri?: string) => Promise<T | undefined>;
|
||||
onDidChange: (cb: vscode.NotificationHandler<vscode.DidChangeConfigurationParams>) => {
|
||||
dispose(): void;
|
||||
};
|
||||
};
|
||||
49
node_modules/@volar/language-server/lib/features/configurations.js
generated
vendored
Normal file
49
node_modules/@volar/language-server/lib/features/configurations.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const vscode = require("vscode-languageserver");
|
||||
function register(server) {
|
||||
const configurations = new Map();
|
||||
const didChangeCallbacks = new Set();
|
||||
server.onInitialized(() => {
|
||||
server.connection.onDidChangeConfiguration(params => {
|
||||
configurations.clear(); // TODO: clear only the configurations that changed
|
||||
for (const cb of didChangeCallbacks) {
|
||||
cb(params);
|
||||
}
|
||||
});
|
||||
const didChangeConfiguration = server.initializeParams.capabilities.workspace?.didChangeConfiguration;
|
||||
if (didChangeConfiguration?.dynamicRegistration) {
|
||||
server.connection.client.register(vscode.DidChangeConfigurationNotification.type);
|
||||
}
|
||||
});
|
||||
return {
|
||||
get,
|
||||
onDidChange,
|
||||
};
|
||||
function get(section, scopeUri) {
|
||||
if (!server.initializeParams.capabilities.workspace?.configuration) {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
const didChangeConfiguration = server.initializeParams.capabilities.workspace?.didChangeConfiguration;
|
||||
if (!scopeUri && didChangeConfiguration) {
|
||||
if (!configurations.has(section)) {
|
||||
configurations.set(section, getConfigurationWorker(section, scopeUri));
|
||||
}
|
||||
return configurations.get(section);
|
||||
}
|
||||
return getConfigurationWorker(section, scopeUri);
|
||||
}
|
||||
function onDidChange(cb) {
|
||||
didChangeCallbacks.add(cb);
|
||||
return {
|
||||
dispose() {
|
||||
didChangeCallbacks.delete(cb);
|
||||
},
|
||||
};
|
||||
}
|
||||
async function getConfigurationWorker(section, scopeUri) {
|
||||
return (await server.connection.workspace.getConfiguration({ scopeUri, section })) ?? undefined /* replace null to undefined */;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=configurations.js.map
|
||||
2
node_modules/@volar/language-server/lib/features/editorFeatures.d.ts
generated
vendored
Normal file
2
node_modules/@volar/language-server/lib/features/editorFeatures.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { LanguageServerState } from '../types';
|
||||
export declare function register(server: LanguageServerState): void;
|
||||
186
node_modules/@volar/language-server/lib/features/editorFeatures.js
generated
vendored
Normal file
186
node_modules/@volar/language-server/lib/features/editorFeatures.js
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_service_1 = require("@volar/language-service");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const protocol_1 = require("../../protocol");
|
||||
function register(server) {
|
||||
server.onInitialize(() => {
|
||||
const { project } = server;
|
||||
const scriptVersions = (0, language_service_1.createUriMap)();
|
||||
const scriptVersionSnapshots = new WeakSet();
|
||||
server.connection.onRequest(protocol_1.GetMatchTsConfigRequest.type, async (params) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.uri);
|
||||
const languageService = (await project.getLanguageService(uri));
|
||||
const tsProject = languageService.context.project.typescript;
|
||||
if (tsProject?.configFileName) {
|
||||
const { configFileName, uriConverter } = tsProject;
|
||||
return { uri: uriConverter.asUri(configFileName).toString() };
|
||||
}
|
||||
});
|
||||
server.connection.onRequest(protocol_1.GetVirtualFileRequest.type, async (document) => {
|
||||
const uri = vscode_uri_1.URI.parse(document.uri);
|
||||
const languageService = (await project.getLanguageService(uri));
|
||||
const documentUri = vscode_uri_1.URI.parse(document.uri);
|
||||
const sourceScript = languageService.context.language.scripts.get(documentUri);
|
||||
if (sourceScript?.generated) {
|
||||
return prune(sourceScript.generated.root);
|
||||
}
|
||||
function prune(virtualCode) {
|
||||
const uri = languageService.context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id);
|
||||
let version = scriptVersions.get(uri) ?? 0;
|
||||
if (!scriptVersionSnapshots.has(virtualCode.snapshot)) {
|
||||
version++;
|
||||
scriptVersions.set(uri, version);
|
||||
scriptVersionSnapshots.add(virtualCode.snapshot);
|
||||
}
|
||||
return {
|
||||
fileUri: sourceScript.id.toString(),
|
||||
virtualCodeId: virtualCode.id,
|
||||
languageId: virtualCode.languageId,
|
||||
embeddedCodes: virtualCode.embeddedCodes?.map(prune) || [],
|
||||
version,
|
||||
disabled: languageService.context.disabledEmbeddedDocumentUris.has(uri),
|
||||
};
|
||||
}
|
||||
});
|
||||
server.connection.onRequest(protocol_1.GetVirtualCodeRequest.type, async (params) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.fileUri);
|
||||
const languageService = (await project.getLanguageService(uri));
|
||||
const sourceScript = languageService.context.language.scripts.get(vscode_uri_1.URI.parse(params.fileUri));
|
||||
const virtualCode = sourceScript?.generated?.embeddedCodes.get(params.virtualCodeId);
|
||||
if (virtualCode) {
|
||||
const mappings = {};
|
||||
for (const [sourceScript, map] of languageService.context.language.maps.forEach(virtualCode)) {
|
||||
mappings[sourceScript.id.toString()] = map.mappings;
|
||||
}
|
||||
return {
|
||||
content: virtualCode.snapshot.getText(0, virtualCode.snapshot.getLength()),
|
||||
mappings,
|
||||
};
|
||||
}
|
||||
});
|
||||
server.connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, async (params) => {
|
||||
// webpack compatibility
|
||||
const _require = eval('require');
|
||||
const fs = _require('fs');
|
||||
const uri = vscode_uri_1.URI.parse(params.uri);
|
||||
const languageService = (await project.getLanguageService(uri));
|
||||
const tsProject = languageService.context.project.typescript;
|
||||
if (tsProject) {
|
||||
const { languageServiceHost } = tsProject;
|
||||
for (const fileName of languageServiceHost.getScriptFileNames()) {
|
||||
if (!fs.existsSync(fileName)) {
|
||||
// global virtual files
|
||||
const snapshot = languageServiceHost.getScriptSnapshot(fileName);
|
||||
if (snapshot) {
|
||||
fs.writeFile(fileName, snapshot.getText(0, snapshot.getLength()), () => { });
|
||||
}
|
||||
}
|
||||
else {
|
||||
const uri = tsProject.uriConverter.asUri(fileName);
|
||||
const sourceScript = languageService.context.language.scripts.get(uri);
|
||||
if (sourceScript?.generated) {
|
||||
const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
|
||||
if (serviceScript) {
|
||||
const { snapshot } = serviceScript.code;
|
||||
fs.writeFile(fileName + serviceScript.extension, snapshot.getText(0, snapshot.getLength()), () => { });
|
||||
}
|
||||
if (sourceScript.generated.languagePlugin.typescript?.getExtraServiceScripts) {
|
||||
for (const extraServiceScript of sourceScript.generated.languagePlugin.typescript.getExtraServiceScripts(uri.toString(), sourceScript.generated.root)) {
|
||||
const { snapshot } = extraServiceScript.code;
|
||||
fs.writeFile(fileName, snapshot.getText(0, snapshot.getLength()), () => { });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
server.connection.onRequest(protocol_1.LoadedTSFilesMetaRequest.type, async () => {
|
||||
const sourceFilesData = new Map();
|
||||
for (const languageService of await project.getExistingLanguageServices()) {
|
||||
const tsLanguageService = languageService.context.inject('typescript/languageService');
|
||||
const program = tsLanguageService?.getProgram();
|
||||
const tsProject = languageService.context.project.typescript;
|
||||
if (program && tsProject) {
|
||||
const { languageServiceHost, configFileName } = tsProject;
|
||||
const projectName = configFileName ?? (languageServiceHost.getCurrentDirectory() + '(inferred)');
|
||||
const sourceFiles = program.getSourceFiles() ?? [];
|
||||
for (const sourceFile of sourceFiles) {
|
||||
if (!sourceFilesData.has(sourceFile)) {
|
||||
let nodes = 0;
|
||||
sourceFile.forEachChild(function walk(node) {
|
||||
nodes++;
|
||||
node.forEachChild(walk);
|
||||
});
|
||||
sourceFilesData.set(sourceFile, {
|
||||
projectNames: [],
|
||||
size: nodes * 128,
|
||||
});
|
||||
}
|
||||
sourceFilesData.get(sourceFile).projectNames.push(projectName);
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
const result = {
|
||||
inputs: {},
|
||||
outputs: {},
|
||||
};
|
||||
for (const [sourceFile, fileData] of sourceFilesData) {
|
||||
let key = fileData.projectNames.sort().join(', ');
|
||||
if (fileData.projectNames.length >= 2) {
|
||||
key = `Shared in ${fileData.projectNames.length} projects (${key})`;
|
||||
}
|
||||
result.outputs[key] ??= {
|
||||
imports: [],
|
||||
exports: [],
|
||||
entryPoint: '',
|
||||
inputs: {},
|
||||
bytes: 0,
|
||||
};
|
||||
result.outputs[key].inputs[sourceFile.fileName] = { bytesInOutput: fileData.size };
|
||||
}
|
||||
return result;
|
||||
});
|
||||
server.connection.onNotification(protocol_1.UpdateVirtualCodeStateNotification.type, async (params) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.fileUri);
|
||||
const languageService = await project.getLanguageService(uri);
|
||||
const virtualFileUri = languageService.context.encodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(params.fileUri), params.virtualCodeId);
|
||||
if (params.disabled) {
|
||||
languageService.context.disabledEmbeddedDocumentUris.set(virtualFileUri, true);
|
||||
}
|
||||
else {
|
||||
languageService.context.disabledEmbeddedDocumentUris.delete(virtualFileUri);
|
||||
}
|
||||
});
|
||||
server.connection.onNotification(protocol_1.UpdateServicePluginStateNotification.type, async (params) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.uri);
|
||||
const languageService = await project.getLanguageService(uri);
|
||||
const plugin = languageService.context.plugins[params.serviceId][1];
|
||||
if (params.disabled) {
|
||||
languageService.context.disabledServicePlugins.add(plugin);
|
||||
}
|
||||
else {
|
||||
languageService.context.disabledServicePlugins.delete(plugin);
|
||||
}
|
||||
});
|
||||
server.connection.onRequest(protocol_1.GetServicePluginsRequest.type, async (params) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.uri);
|
||||
const languageService = await project.getLanguageService(uri);
|
||||
const result = [];
|
||||
for (let pluginIndex = 0; pluginIndex < languageService.context.plugins.length; pluginIndex++) {
|
||||
const plugin = languageService.context.plugins[pluginIndex];
|
||||
result.push({
|
||||
id: pluginIndex,
|
||||
name: plugin[0].name,
|
||||
disabled: languageService.context.disabledServicePlugins.has(plugin[1]),
|
||||
features: Object.keys(plugin[1]),
|
||||
});
|
||||
}
|
||||
return result;
|
||||
});
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=editorFeatures.js.map
|
||||
8
node_modules/@volar/language-server/lib/features/fileSystem.d.ts
generated
vendored
Normal file
8
node_modules/@volar/language-server/lib/features/fileSystem.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { FileSystem } from '@volar/language-service';
|
||||
import { URI } from 'vscode-uri';
|
||||
export declare function register(documents: ReturnType<typeof import('./textDocuments').register>, fileWatcher: ReturnType<typeof import('./fileWatcher').register>): {
|
||||
readFile(uri: URI): string | Thenable<string | undefined>;
|
||||
stat(uri: URI): import("@volar/language-service").FileStat | Thenable<import("@volar/language-service").FileStat | undefined>;
|
||||
readDirectory(uri: URI): import("@volar/language-service").ProviderResult<[string, import("@volar/language-service").FileType][]>;
|
||||
install(scheme: string, provider: FileSystem): void;
|
||||
};
|
||||
61
node_modules/@volar/language-server/lib/features/fileSystem.js
generated
vendored
Normal file
61
node_modules/@volar/language-server/lib/features/fileSystem.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_service_1 = require("@volar/language-service");
|
||||
const vscode = require("vscode-languageserver");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
function register(documents, fileWatcher) {
|
||||
const providers = new Map();
|
||||
const readFileCache = (0, language_service_1.createUriMap)();
|
||||
const statCache = (0, language_service_1.createUriMap)();
|
||||
const readDirectoryCache = (0, language_service_1.createUriMap)();
|
||||
documents.onDidSave(({ document }) => {
|
||||
const uri = vscode_uri_1.URI.parse(document.uri);
|
||||
readFileCache.set(uri, document.getText());
|
||||
statCache.delete(uri);
|
||||
});
|
||||
fileWatcher.onDidChangeWatchedFiles(({ changes }) => {
|
||||
for (const change of changes) {
|
||||
const changeUri = vscode_uri_1.URI.parse(change.uri);
|
||||
const dir = vscode_uri_1.URI.parse(change.uri.substring(0, change.uri.lastIndexOf('/')));
|
||||
if (change.type === vscode.FileChangeType.Deleted) {
|
||||
readFileCache.set(changeUri, undefined);
|
||||
statCache.set(changeUri, undefined);
|
||||
readDirectoryCache.delete(dir);
|
||||
}
|
||||
else if (change.type === vscode.FileChangeType.Changed) {
|
||||
readFileCache.delete(changeUri);
|
||||
statCache.delete(changeUri);
|
||||
}
|
||||
else if (change.type === vscode.FileChangeType.Created) {
|
||||
readFileCache.delete(changeUri);
|
||||
statCache.delete(changeUri);
|
||||
readDirectoryCache.delete(dir);
|
||||
}
|
||||
}
|
||||
});
|
||||
return {
|
||||
readFile(uri) {
|
||||
if (!readFileCache.has(uri)) {
|
||||
readFileCache.set(uri, providers.get(uri.scheme)?.readFile(uri));
|
||||
}
|
||||
return readFileCache.get(uri);
|
||||
},
|
||||
stat(uri) {
|
||||
if (!statCache.has(uri)) {
|
||||
statCache.set(uri, providers.get(uri.scheme)?.stat(uri));
|
||||
}
|
||||
return statCache.get(uri);
|
||||
},
|
||||
readDirectory(uri) {
|
||||
if (!readDirectoryCache.has(uri)) {
|
||||
readDirectoryCache.set(uri, providers.get(uri.scheme)?.readDirectory(uri) ?? []);
|
||||
}
|
||||
return readDirectoryCache.get(uri);
|
||||
},
|
||||
install(scheme, provider) {
|
||||
providers.set(scheme, provider);
|
||||
},
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=fileSystem.js.map
|
||||
9
node_modules/@volar/language-server/lib/features/fileWatcher.d.ts
generated
vendored
Normal file
9
node_modules/@volar/language-server/lib/features/fileWatcher.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Disposable } from '@volar/language-service';
|
||||
import * as vscode from 'vscode-languageserver';
|
||||
import { LanguageServerState } from '../types';
|
||||
export declare function register(server: LanguageServerState): {
|
||||
watchFiles: (patterns: string[]) => Promise<Disposable>;
|
||||
onDidChangeWatchedFiles: (cb: vscode.NotificationHandler<vscode.DidChangeWatchedFilesParams>) => {
|
||||
dispose: () => void;
|
||||
};
|
||||
};
|
||||
63
node_modules/@volar/language-server/lib/features/fileWatcher.js
generated
vendored
Normal file
63
node_modules/@volar/language-server/lib/features/fileWatcher.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const vscode = require("vscode-languageserver");
|
||||
function register(server) {
|
||||
let watchFilesDisposableCounter = 0;
|
||||
let watchFilesDisposable;
|
||||
const didChangeWatchedFilesCallbacks = new Set();
|
||||
return {
|
||||
watchFiles,
|
||||
onDidChangeWatchedFiles,
|
||||
};
|
||||
async function watchFiles(patterns) {
|
||||
const disposables = [];
|
||||
const didChangeWatchedFiles = server.initializeParams.capabilities.workspace?.didChangeWatchedFiles;
|
||||
const fileOperations = server.initializeParams.capabilities.workspace?.fileOperations;
|
||||
if (didChangeWatchedFiles) {
|
||||
if (watchFilesDisposableCounter === 0) {
|
||||
watchFilesDisposable = server.connection.onDidChangeWatchedFiles(e => {
|
||||
for (const cb of didChangeWatchedFilesCallbacks) {
|
||||
cb(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
watchFilesDisposableCounter++;
|
||||
disposables.push({
|
||||
dispose() {
|
||||
watchFilesDisposableCounter--;
|
||||
if (watchFilesDisposableCounter === 0) {
|
||||
watchFilesDisposable?.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (didChangeWatchedFiles?.dynamicRegistration) {
|
||||
disposables.push(await server.connection.client.register(vscode.DidChangeWatchedFilesNotification.type, {
|
||||
watchers: patterns.map(pattern => ({ globPattern: pattern })),
|
||||
}));
|
||||
}
|
||||
if (fileOperations?.dynamicRegistration && fileOperations.willRename) {
|
||||
disposables.push(await server.connection.client.register(vscode.WillRenameFilesRequest.type, {
|
||||
filters: patterns.map(pattern => ({ pattern: { glob: pattern } })),
|
||||
}));
|
||||
}
|
||||
return {
|
||||
dispose() {
|
||||
for (const disposable of disposables) {
|
||||
disposable.dispose();
|
||||
}
|
||||
disposables.length = 0;
|
||||
},
|
||||
};
|
||||
}
|
||||
function onDidChangeWatchedFiles(cb) {
|
||||
didChangeWatchedFilesCallbacks.add(cb);
|
||||
return {
|
||||
dispose: () => {
|
||||
didChangeWatchedFilesCallbacks.delete(cb);
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=fileWatcher.js.map
|
||||
4
node_modules/@volar/language-server/lib/features/languageFeatures.d.ts
generated
vendored
Normal file
4
node_modules/@volar/language-server/lib/features/languageFeatures.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { LanguageServerState } from '../types.js';
|
||||
export declare function register(server: LanguageServerState, documents: ReturnType<typeof import('./textDocuments')['register']>, configurations: ReturnType<typeof import('./configurations')['register']>): {
|
||||
requestRefresh: (clearDiagnostics: boolean) => Promise<void>;
|
||||
};
|
||||
768
node_modules/@volar/language-server/lib/features/languageFeatures.js
generated
vendored
Normal file
768
node_modules/@volar/language-server/lib/features/languageFeatures.js
generated
vendored
Normal file
@@ -0,0 +1,768 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_service_1 = require("@volar/language-service");
|
||||
const vscode = require("vscode-languageserver");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const protocol_1 = require("../../protocol");
|
||||
const reportedCapabilities = new Set();
|
||||
function register(server, documents, configurations) {
|
||||
// Diagnostics support
|
||||
let refreshReq = 0;
|
||||
let updateDiagnosticsBatchReq = 0;
|
||||
const refreshHandlers = [];
|
||||
server.onInitialize(serverCapabilities => {
|
||||
let lastCompleteUri;
|
||||
let lastCompleteLs;
|
||||
let lastCodeLensLs;
|
||||
let lastCodeActionLs;
|
||||
let lastCallHierarchyLs;
|
||||
let lastTypeHierarchyLs;
|
||||
let lastDocumentLinkLs;
|
||||
let lastInlayHintLs;
|
||||
let languageServiceToId = new WeakMap();
|
||||
let currentLanguageServiceId = 0;
|
||||
const languageServiceById = new Map();
|
||||
const { languageServicePlugins, project, initializeParams } = server;
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.selectionRangeProvider)) {
|
||||
serverCapabilities.selectionRangeProvider = true;
|
||||
server.connection.onSelectionRanges(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getSelectionRanges(uri, params.positions, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.foldingRangeProvider)) {
|
||||
serverCapabilities.foldingRangeProvider = true;
|
||||
server.connection.onFoldingRanges(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getFoldingRanges(uri, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.linkedEditingRangeProvider)) {
|
||||
serverCapabilities.linkedEditingRangeProvider = true;
|
||||
server.connection.languages.onLinkedEditingRange(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getLinkedEditingRanges(uri, params.position, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.colorProvider)) {
|
||||
serverCapabilities.colorProvider = true;
|
||||
server.connection.onDocumentColor(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getDocumentColors(uri, token);
|
||||
});
|
||||
});
|
||||
server.connection.onColorPresentation(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getColorPresentations(uri, params.color, params.range, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.documentSymbolProvider)) {
|
||||
serverCapabilities.documentSymbolProvider = true;
|
||||
server.connection.onDocumentSymbol(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getDocumentSymbols(uri, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.documentFormattingProvider)) {
|
||||
serverCapabilities.documentFormattingProvider = true;
|
||||
serverCapabilities.documentRangeFormattingProvider = true;
|
||||
server.connection.onDocumentFormatting(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getDocumentFormattingEdits(uri, params.options, undefined, undefined, token);
|
||||
});
|
||||
});
|
||||
server.connection.onDocumentRangeFormatting(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getDocumentFormattingEdits(uri, params.options, params.range, undefined, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.referencesProvider)) {
|
||||
serverCapabilities.referencesProvider = true;
|
||||
server.connection.onReferences(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getReferences(uri, params.position, { includeDeclaration: true }, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.implementationProvider)) {
|
||||
serverCapabilities.implementationProvider = true;
|
||||
server.connection.onImplementation(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, async (languageService) => {
|
||||
const definitions = await languageService.getImplementations(uri, params.position, token);
|
||||
return handleDefinitions(initializeParams, 'implementation', definitions ?? []);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.declarationProvider)) {
|
||||
serverCapabilities.declarationProvider = true;
|
||||
server.connection.onDeclaration(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, async (languageService) => {
|
||||
const definitions = await languageService.getDeclaration(uri, params.position, token);
|
||||
return handleDefinitions(initializeParams, 'declaration', definitions ?? []);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.definitionProvider)) {
|
||||
serverCapabilities.definitionProvider = true;
|
||||
server.connection.onDefinition(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, async (languageService) => {
|
||||
const definitions = await languageService.getDefinition(uri, params.position, token);
|
||||
return handleDefinitions(initializeParams, 'definition', definitions ?? []);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.typeDefinitionProvider)) {
|
||||
serverCapabilities.typeDefinitionProvider = true;
|
||||
server.connection.onTypeDefinition(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, async (languageService) => {
|
||||
const definitions = await languageService.getTypeDefinition(uri, params.position, token);
|
||||
return handleDefinitions(initializeParams, 'typeDefinition', definitions ?? []);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.callHierarchyProvider)) {
|
||||
serverCapabilities.callHierarchyProvider = true;
|
||||
server.connection.languages.callHierarchy.onPrepare(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
lastCallHierarchyLs = languageService;
|
||||
return languageService.getCallHierarchyItems(uri, params.position, token);
|
||||
}) ?? [];
|
||||
});
|
||||
server.connection.languages.callHierarchy.onIncomingCalls(async (params, token) => {
|
||||
return await lastCallHierarchyLs?.getCallHierarchyIncomingCalls(params.item, token) ?? [];
|
||||
});
|
||||
server.connection.languages.callHierarchy.onOutgoingCalls(async (params, token) => {
|
||||
return await lastCallHierarchyLs?.getCallHierarchyOutgoingCalls(params.item, token) ?? [];
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.typeHierarchyProvider)) {
|
||||
serverCapabilities.typeHierarchyProvider = true;
|
||||
server.connection.languages.typeHierarchy.onPrepare(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
lastTypeHierarchyLs = languageService;
|
||||
return languageService.getTypeHierarchyItems(uri, params.position, token);
|
||||
}) ?? [];
|
||||
});
|
||||
server.connection.languages.typeHierarchy.onSupertypes(async (params, token) => {
|
||||
return await lastTypeHierarchyLs?.getTypeHierarchySupertypes(params.item, token) ?? [];
|
||||
});
|
||||
server.connection.languages.typeHierarchy.onSubtypes(async (params, token) => {
|
||||
return await lastTypeHierarchyLs?.getTypeHierarchySubtypes(params.item, token) ?? [];
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.hoverProvider)) {
|
||||
serverCapabilities.hoverProvider = true;
|
||||
server.connection.onHover(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getHover(uri, params.position, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.documentHighlightProvider)) {
|
||||
serverCapabilities.documentHighlightProvider = true;
|
||||
server.connection.onDocumentHighlight(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getDocumentHighlights(uri, params.position, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.workspaceSymbolProvider)) {
|
||||
serverCapabilities.workspaceSymbolProvider = {};
|
||||
server.connection.onWorkspaceSymbol(async (params, token) => {
|
||||
let languageServices = await project.getExistingLanguageServices();
|
||||
if (!languageServices.length) {
|
||||
for (const document of documents.all()) {
|
||||
await project.getLanguageService(vscode_uri_1.URI.parse(document.uri));
|
||||
}
|
||||
languageServices = await project.getExistingLanguageServices();
|
||||
}
|
||||
const symbols = [];
|
||||
for (const languageService of languageServices) {
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
let languageServiceId = languageServiceToId.get(languageService);
|
||||
if (languageServiceId === undefined) {
|
||||
languageServiceId = currentLanguageServiceId;
|
||||
languageServiceToId.set(languageService, languageServiceId);
|
||||
languageServiceById.set(languageServiceId, new WeakRef(languageService));
|
||||
}
|
||||
const languageServiceResult = await languageService.getWorkspaceSymbols(params.query, token);
|
||||
for (const symbol of languageServiceResult) {
|
||||
symbol.data = {
|
||||
languageServiceId,
|
||||
originalData: symbol.data,
|
||||
};
|
||||
}
|
||||
symbols.push(...await languageService.getWorkspaceSymbols(params.query, token));
|
||||
}
|
||||
return symbols;
|
||||
});
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.workspaceSymbolProvider?.resolveProvider)) {
|
||||
serverCapabilities.workspaceSymbolProvider.resolveProvider = true;
|
||||
server.connection.onWorkspaceSymbolResolve(async (symbol, token) => {
|
||||
const languageServiceId = symbol.data?.languageServiceId;
|
||||
const languageService = languageServiceById.get(languageServiceId)?.deref();
|
||||
if (!languageService) {
|
||||
return symbol;
|
||||
}
|
||||
symbol.data = symbol.data?.originalData;
|
||||
return await languageService.resolveWorkspaceSymbol?.(symbol, token);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.renameProvider)) {
|
||||
serverCapabilities.renameProvider = {};
|
||||
server.connection.onRenameRequest(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getRenameEdits(uri, params.position, params.newName, token);
|
||||
});
|
||||
});
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.renameProvider?.prepareProvider)) {
|
||||
serverCapabilities.renameProvider.prepareProvider = true;
|
||||
server.connection.onPrepareRename(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, async (languageService) => {
|
||||
const result = await languageService.getRenameRange(uri, params.position, token);
|
||||
if (result && 'message' in result) {
|
||||
return new vscode.ResponseError(0, result.message);
|
||||
}
|
||||
return result;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.documentLinkProvider)) {
|
||||
serverCapabilities.documentLinkProvider = {};
|
||||
server.connection.onDocumentLinks(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
lastDocumentLinkLs = languageService;
|
||||
return languageService.getDocumentLinks(uri, token);
|
||||
});
|
||||
});
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.documentLinkProvider?.resolveProvider)) {
|
||||
serverCapabilities.documentLinkProvider.resolveProvider = true;
|
||||
server.connection.onDocumentLinkResolve(async (link, token) => {
|
||||
return await lastDocumentLinkLs?.resolveDocumentLink(link, token);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.codeLensProvider)) {
|
||||
serverCapabilities.codeLensProvider = {};
|
||||
server.connection.onCodeLens(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
lastCodeLensLs = languageService;
|
||||
return languageService.getCodeLenses(uri, token);
|
||||
});
|
||||
});
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.codeLensProvider?.resolveProvider)) {
|
||||
serverCapabilities.codeLensProvider.resolveProvider = true;
|
||||
server.connection.onCodeLensResolve(async (codeLens, token) => {
|
||||
return await lastCodeLensLs?.resolveCodeLens(codeLens, token) ?? codeLens;
|
||||
});
|
||||
}
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.inlayHintProvider)) {
|
||||
serverCapabilities.inlayHintProvider = {};
|
||||
server.connection.languages.inlayHint.on(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
lastInlayHintLs = languageService;
|
||||
return languageService.getInlayHints(uri, params.range, token);
|
||||
});
|
||||
});
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.inlayHintProvider?.resolveProvider)) {
|
||||
serverCapabilities.inlayHintProvider.resolveProvider = true;
|
||||
server.connection.languages.inlayHint.resolve(async (hint, token) => {
|
||||
return await lastInlayHintLs?.resolveInlayHint(hint, token) ?? hint;
|
||||
});
|
||||
}
|
||||
refreshHandlers.push(() => {
|
||||
if (initializeParams.capabilities.workspace?.inlayHint?.refreshSupport) {
|
||||
server.connection.languages.inlayHint.refresh();
|
||||
}
|
||||
else {
|
||||
wranCapabilitiesNotSupported('workspace.inlayHint.refreshSupport');
|
||||
}
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.signatureHelpProvider)) {
|
||||
serverCapabilities.signatureHelpProvider = {
|
||||
triggerCharacters: [...new Set(languageServicePlugins.map(({ capabilities }) => capabilities.signatureHelpProvider?.triggerCharacters ?? []).flat())],
|
||||
retriggerCharacters: [...new Set(languageServicePlugins.map(({ capabilities }) => capabilities.signatureHelpProvider?.retriggerCharacters ?? []).flat())],
|
||||
};
|
||||
server.connection.onSignatureHelp(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getSignatureHelp(uri, params.position, params.context, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.completionProvider)) {
|
||||
serverCapabilities.completionProvider = {
|
||||
triggerCharacters: [...new Set(languageServicePlugins.map(({ capabilities }) => capabilities.completionProvider?.triggerCharacters ?? []).flat())],
|
||||
};
|
||||
server.connection.onCompletion(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, async (languageService) => {
|
||||
lastCompleteUri = params.textDocument.uri;
|
||||
lastCompleteLs = languageService;
|
||||
const list = await languageService.getCompletionItems(uri, params.position, params.context, token);
|
||||
list.items = list.items.map(item => handleCompletionItem(initializeParams, item));
|
||||
return list;
|
||||
});
|
||||
});
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.completionProvider?.resolveProvider)) {
|
||||
serverCapabilities.completionProvider.resolveProvider = true;
|
||||
server.connection.onCompletionResolve(async (item, token) => {
|
||||
if (lastCompleteUri && lastCompleteLs) {
|
||||
item = await lastCompleteLs.resolveCompletionItem(item, token);
|
||||
item = handleCompletionItem(initializeParams, item);
|
||||
}
|
||||
return item;
|
||||
});
|
||||
}
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.semanticTokensProvider)) {
|
||||
serverCapabilities.semanticTokensProvider = {
|
||||
range: true,
|
||||
full: false, // TODO: enable it after testing
|
||||
legend: {
|
||||
tokenTypes: [...new Set(languageServicePlugins.map(({ capabilities }) => capabilities.semanticTokensProvider?.legend?.tokenTypes ?? []).flat())],
|
||||
tokenModifiers: [...new Set(languageServicePlugins.map(({ capabilities }) => capabilities.semanticTokensProvider?.legend?.tokenModifiers ?? []).flat())],
|
||||
},
|
||||
};
|
||||
server.connection.languages.semanticTokens.on(async (params, token, _, resultProgress) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, async (languageService) => {
|
||||
return await languageService?.getSemanticTokens(uri, undefined, serverCapabilities.semanticTokensProvider.legend, tokens => resultProgress?.report(tokens), token);
|
||||
}) ?? { data: [] };
|
||||
});
|
||||
server.connection.languages.semanticTokens.onRange(async (params, token, _, resultProgress) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, async (languageService) => {
|
||||
return await languageService?.getSemanticTokens(uri, params.range, serverCapabilities.semanticTokensProvider.legend, tokens => resultProgress?.report(tokens), token);
|
||||
}) ?? { data: [] };
|
||||
});
|
||||
refreshHandlers.push(() => {
|
||||
if (initializeParams.capabilities.workspace?.semanticTokens?.refreshSupport) {
|
||||
server.connection.languages.semanticTokens.refresh();
|
||||
}
|
||||
else {
|
||||
wranCapabilitiesNotSupported('workspace.semanticTokens.refreshSupport');
|
||||
}
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.codeActionProvider)) {
|
||||
serverCapabilities.codeActionProvider = {
|
||||
codeActionKinds: languageServicePlugins.some(({ capabilities }) => capabilities.codeActionProvider?.codeActionKinds)
|
||||
? [...new Set(languageServicePlugins.map(({ capabilities }) => capabilities.codeActionProvider?.codeActionKinds ?? []).flat())]
|
||||
: undefined,
|
||||
};
|
||||
server.connection.onCodeAction(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, async (languageService) => {
|
||||
lastCodeActionLs = languageService;
|
||||
let codeActions = await languageService.getCodeActions(uri, params.range, params.context, token) ?? [];
|
||||
for (const codeAction of codeActions) {
|
||||
if (codeAction.data && typeof codeAction.data === 'object') {
|
||||
codeAction.data.uri = params.textDocument.uri;
|
||||
}
|
||||
else {
|
||||
codeAction.data = { uri: params.textDocument.uri };
|
||||
}
|
||||
}
|
||||
if (!initializeParams.capabilities.textDocument?.codeAction?.disabledSupport
|
||||
&& codeActions.some(codeAction => !codeAction.disabled)) {
|
||||
codeActions = codeActions.filter(codeAction => !codeAction.disabled);
|
||||
wranCapabilitiesNotSupported('textDocument.codeAction.disabledSupport');
|
||||
}
|
||||
return codeActions;
|
||||
});
|
||||
});
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.codeActionProvider?.resolveProvider)) {
|
||||
serverCapabilities.codeActionProvider.resolveProvider = true;
|
||||
server.connection.onCodeActionResolve(async (codeAction, token) => {
|
||||
return await lastCodeActionLs?.resolveCodeAction(codeAction, token) ?? codeAction;
|
||||
});
|
||||
}
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.documentOnTypeFormattingProvider)) {
|
||||
serverCapabilities.documentOnTypeFormattingProvider = {
|
||||
firstTriggerCharacter: [...new Set(languageServicePlugins.map(({ capabilities }) => capabilities.documentOnTypeFormattingProvider?.triggerCharacters ?? []).flat())][0],
|
||||
moreTriggerCharacter: [...new Set(languageServicePlugins.map(({ capabilities }) => capabilities.documentOnTypeFormattingProvider?.triggerCharacters ?? []).flat())].slice(1),
|
||||
};
|
||||
server.connection.onDocumentOnTypeFormatting(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getDocumentFormattingEdits(uri, params.options, undefined, params, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.executeCommandProvider)) {
|
||||
serverCapabilities.executeCommandProvider = {
|
||||
commands: [...new Set(languageServicePlugins.map(({ capabilities }) => capabilities.executeCommandProvider?.commands ?? []).flat())],
|
||||
};
|
||||
server.connection.onExecuteCommand(async (params, token) => {
|
||||
let languageServices = await project.getExistingLanguageServices();
|
||||
if (!languageServices.length) {
|
||||
for (const document of documents.all()) {
|
||||
await project.getLanguageService(vscode_uri_1.URI.parse(document.uri));
|
||||
}
|
||||
languageServices = await project.getExistingLanguageServices();
|
||||
}
|
||||
for (const languageService of languageServices) {
|
||||
if (languageService.executeCommand && languageService.commands.includes(params.command)) {
|
||||
try {
|
||||
return await languageService.executeCommand(params.command, params.arguments ?? [], token);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.monikerProvider)) {
|
||||
serverCapabilities.monikerProvider = true;
|
||||
server.connection.languages.moniker.on(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getMoniker(uri, params.position, token);
|
||||
}) ?? null;
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.inlineValueProvider)) {
|
||||
serverCapabilities.inlineValueProvider = true;
|
||||
server.connection.languages.inlineValue.on(async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getInlineValue(uri, params.range, params.context, token);
|
||||
});
|
||||
});
|
||||
refreshHandlers.push(() => {
|
||||
if (initializeParams.capabilities.workspace?.inlineValue?.refreshSupport) {
|
||||
server.connection.languages.inlineValue.refresh();
|
||||
}
|
||||
else {
|
||||
wranCapabilitiesNotSupported('workspace.inlineValue.refreshSupport');
|
||||
}
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.autoInsertionProvider)) {
|
||||
const triggerCharacterToConfigurationSections = new Map();
|
||||
const tryAdd = (char, section) => {
|
||||
let sectionSet = triggerCharacterToConfigurationSections.get(char);
|
||||
if (!sectionSet) {
|
||||
triggerCharacterToConfigurationSections.set(char, sectionSet = new Set());
|
||||
}
|
||||
if (section) {
|
||||
sectionSet.add(section);
|
||||
}
|
||||
};
|
||||
for (const { capabilities } of languageServicePlugins) {
|
||||
if (capabilities.autoInsertionProvider) {
|
||||
const { triggerCharacters, configurationSections } = capabilities.autoInsertionProvider;
|
||||
if (configurationSections) {
|
||||
if (configurationSections.length !== triggerCharacters.length) {
|
||||
throw new Error('configurationSections.length !== triggerCharacters.length');
|
||||
}
|
||||
for (let i = 0; i < configurationSections.length; i++) {
|
||||
tryAdd(triggerCharacters[i], configurationSections[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (const char of triggerCharacters) {
|
||||
tryAdd(char);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
serverCapabilities.experimental ??= {};
|
||||
serverCapabilities.experimental.autoInsertionProvider = {
|
||||
triggerCharacters: [],
|
||||
configurationSections: [],
|
||||
};
|
||||
for (const [char, sections] of triggerCharacterToConfigurationSections) {
|
||||
if (sections.size) {
|
||||
serverCapabilities.experimental.autoInsertionProvider.triggerCharacters.push(char);
|
||||
serverCapabilities.experimental.autoInsertionProvider.configurationSections.push([...sections]);
|
||||
}
|
||||
else {
|
||||
serverCapabilities.experimental.autoInsertionProvider.triggerCharacters.push(char);
|
||||
serverCapabilities.experimental.autoInsertionProvider.configurationSections.push(null);
|
||||
}
|
||||
}
|
||||
server.connection.onRequest(protocol_1.AutoInsertRequest.type, async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getAutoInsertSnippet(uri, params.selection, params.change, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.fileRenameEditsProvider)) {
|
||||
serverCapabilities.experimental ??= {};
|
||||
serverCapabilities.experimental.fileRenameEditsProvider = true;
|
||||
server.connection.workspace.onWillRenameFiles(async (params, token) => {
|
||||
const _edits = await Promise.all(params.files.map(async (file) => {
|
||||
const oldUri = vscode_uri_1.URI.parse(file.oldUri);
|
||||
const newUri = vscode_uri_1.URI.parse(file.newUri);
|
||||
return await worker(oldUri, token, languageService => {
|
||||
return languageService.getFileRenameEdits(oldUri, newUri, token) ?? null;
|
||||
}) ?? null;
|
||||
}));
|
||||
const edits = _edits.filter((edit) => !!edit);
|
||||
if (edits.length) {
|
||||
(0, language_service_1.mergeWorkspaceEdits)(edits[0], ...edits.slice(1));
|
||||
return edits[0];
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.fileReferencesProvider)) {
|
||||
serverCapabilities.experimental ??= {};
|
||||
serverCapabilities.experimental.fileReferencesProvider = true;
|
||||
server.connection.onRequest(protocol_1.FindFileReferenceRequest.type, async (params, token) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
return await worker(uri, token, languageService => {
|
||||
return languageService.getFileReferences(uri, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (languageServicePlugins.some(({ capabilities }) => capabilities.documentDropEditsProvider)) {
|
||||
serverCapabilities.experimental ??= {};
|
||||
serverCapabilities.experimental.documentDropEditsProvider = true;
|
||||
server.connection.onRequest(protocol_1.DocumentDropRequest.type, async ({ textDocument, position, dataTransfer }, token) => {
|
||||
const dataTransferMap = new Map();
|
||||
for (const item of dataTransfer) {
|
||||
dataTransferMap.set(item.mimeType, {
|
||||
value: item.value,
|
||||
asString() {
|
||||
return server.connection.sendRequest(protocol_1.DocumentDrop_DataTransferItemAsStringRequest.type, { mimeType: item.mimeType });
|
||||
},
|
||||
asFile() {
|
||||
if (item.file) {
|
||||
return {
|
||||
name: item.file.name,
|
||||
uri: item.file.uri,
|
||||
data() {
|
||||
return server.connection.sendRequest(protocol_1.DocumentDrop_DataTransferItemFileDataRequest.type, { mimeType: item.mimeType });
|
||||
},
|
||||
};
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
const uri = vscode_uri_1.URI.parse(textDocument.uri);
|
||||
const languageService = (await project.getLanguageService(uri));
|
||||
return languageService.getDocumentDropEdits(uri, position, dataTransferMap, token);
|
||||
});
|
||||
}
|
||||
// Diagnostic support
|
||||
const supportsDiagnosticPull = !!initializeParams.capabilities.workspace?.diagnostics;
|
||||
const diagnosticProvider = languageServicePlugins.some(({ capabilities }) => !!capabilities.diagnosticProvider);
|
||||
const interFileDependencies = languageServicePlugins.some(({ capabilities }) => capabilities.diagnosticProvider?.interFileDependencies);
|
||||
const workspaceDiagnostics = languageServicePlugins.some(({ capabilities }) => capabilities.diagnosticProvider?.workspaceDiagnostics);
|
||||
if (diagnosticProvider) {
|
||||
if (supportsDiagnosticPull && !interFileDependencies) {
|
||||
serverCapabilities.diagnosticProvider = {
|
||||
// Unreliable, see https://github.com/microsoft/vscode-languageserver-node/issues/848#issuecomment-2189521060
|
||||
interFileDependencies: false,
|
||||
workspaceDiagnostics,
|
||||
};
|
||||
refreshHandlers.push(() => {
|
||||
if (initializeParams.capabilities.workspace?.diagnostics?.refreshSupport) {
|
||||
server.connection.languages.diagnostics.refresh();
|
||||
}
|
||||
else {
|
||||
wranCapabilitiesNotSupported('workspace.diagnostics.refreshSupport');
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
documents.onDidChangeContent(({ document }) => {
|
||||
const changedDocument = documents.get(vscode_uri_1.URI.parse(document.uri));
|
||||
if (!changedDocument) {
|
||||
return;
|
||||
}
|
||||
if (interFileDependencies) {
|
||||
const remainingDocuments = [...documents.all()].filter(doc => doc !== changedDocument);
|
||||
updateDiagnosticsBatch(project, [changedDocument, ...remainingDocuments]);
|
||||
}
|
||||
else {
|
||||
updateDiagnosticsBatch(project, [changedDocument]);
|
||||
}
|
||||
});
|
||||
documents.onDidClose(({ document }) => {
|
||||
server.connection.sendDiagnostics({ uri: document.uri, diagnostics: [] });
|
||||
});
|
||||
configurations.onDidChange(() => requestRefresh(false));
|
||||
refreshHandlers.push(async (clearDiagnostics) => {
|
||||
if (clearDiagnostics) {
|
||||
for (const document of documents.all()) {
|
||||
server.connection.sendDiagnostics({ uri: document.uri, diagnostics: [] });
|
||||
}
|
||||
}
|
||||
await updateDiagnosticsBatch(project, [...documents.all()]);
|
||||
});
|
||||
}
|
||||
server.connection.languages.diagnostics.on(async (params, token, _workDoneProgressReporter, resultProgressReporter) => {
|
||||
const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
|
||||
const result = await worker(uri, token, languageService => {
|
||||
return languageService.getDiagnostics(uri, errors => {
|
||||
// resultProgressReporter is undefined in vscode
|
||||
resultProgressReporter?.report({
|
||||
relatedDocuments: {
|
||||
[params.textDocument.uri]: {
|
||||
kind: vscode.DocumentDiagnosticReportKind.Full,
|
||||
items: errors,
|
||||
},
|
||||
},
|
||||
});
|
||||
}, token);
|
||||
});
|
||||
return {
|
||||
kind: vscode.DocumentDiagnosticReportKind.Full,
|
||||
items: result ?? [],
|
||||
};
|
||||
});
|
||||
}
|
||||
if (workspaceDiagnostics) {
|
||||
server.connection.languages.diagnostics.onWorkspace(async (_params, token) => {
|
||||
let languageServices = await project.getExistingLanguageServices();
|
||||
if (!languageServices.length) {
|
||||
for (const document of documents.all()) {
|
||||
await project.getLanguageService(vscode_uri_1.URI.parse(document.uri));
|
||||
}
|
||||
languageServices = await project.getExistingLanguageServices();
|
||||
}
|
||||
const items = [];
|
||||
for (const languageService of languageServices) {
|
||||
if (token.isCancellationRequested) {
|
||||
break;
|
||||
}
|
||||
const result = await languageService.getWorkspaceDiagnostics(token);
|
||||
items.push(...result);
|
||||
}
|
||||
return { items };
|
||||
});
|
||||
}
|
||||
});
|
||||
return { requestRefresh };
|
||||
async function requestRefresh(clearDiagnostics) {
|
||||
const req = ++refreshReq;
|
||||
const delay = 250;
|
||||
await sleep(delay);
|
||||
if (req !== refreshReq) {
|
||||
return;
|
||||
}
|
||||
for (const handler of refreshHandlers) {
|
||||
handler(clearDiagnostics);
|
||||
}
|
||||
}
|
||||
async function updateDiagnosticsBatch(project, documents) {
|
||||
const req = ++updateDiagnosticsBatchReq;
|
||||
const delay = 250;
|
||||
const token = {
|
||||
get isCancellationRequested() {
|
||||
return req !== updateDiagnosticsBatchReq;
|
||||
},
|
||||
onCancellationRequested: vscode.Event.None,
|
||||
};
|
||||
for (const doc of documents) {
|
||||
await sleep(delay);
|
||||
if (token.isCancellationRequested) {
|
||||
break;
|
||||
}
|
||||
await updateDiagnostics(project, vscode_uri_1.URI.parse(doc.uri), doc.version, token);
|
||||
}
|
||||
}
|
||||
async function updateDiagnostics(project, uri, version, token) {
|
||||
const languageService = await project.getLanguageService(uri);
|
||||
const diagnostics = await languageService.getDiagnostics(uri, diagnostics => server.connection.sendDiagnostics({ uri: uri.toString(), diagnostics, version }), token);
|
||||
if (!token.isCancellationRequested) {
|
||||
server.connection.sendDiagnostics({ uri: uri.toString(), diagnostics, version });
|
||||
}
|
||||
}
|
||||
function worker(uri, token, cb) {
|
||||
return new Promise(resolve => {
|
||||
server.env.timer.setImmediate(async () => {
|
||||
if (token.isCancellationRequested) {
|
||||
resolve(undefined);
|
||||
return;
|
||||
}
|
||||
const languageService = (await server.project.getLanguageService((0, language_service_1.decodeEmbeddedDocumentUri)(uri)?.[0] ?? uri));
|
||||
const result = await cb(languageService);
|
||||
if (token.isCancellationRequested) {
|
||||
resolve(undefined);
|
||||
return;
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
});
|
||||
}
|
||||
function handleCompletionItem(initializeParams, item) {
|
||||
const snippetSupport = initializeParams.capabilities.textDocument?.completion?.completionItem?.snippetSupport ?? false;
|
||||
const insertReplaceSupport = initializeParams.capabilities.textDocument?.completion?.completionItem?.insertReplaceSupport ?? false;
|
||||
if (!snippetSupport && item.insertTextFormat === vscode.InsertTextFormat.Snippet) {
|
||||
item.insertTextFormat = vscode.InsertTextFormat.PlainText;
|
||||
if (item.insertText) {
|
||||
item.insertText = item.insertText.replace(/\$\d+/g, '');
|
||||
item.insertText = item.insertText.replace(/\${\d+:([^}]*)}/g, '');
|
||||
}
|
||||
wranCapabilitiesNotSupported('textDocument.completion.completionItem.snippetSupport');
|
||||
}
|
||||
if (!insertReplaceSupport && item.textEdit && vscode.InsertReplaceEdit.is(item.textEdit)) {
|
||||
item.textEdit = vscode.TextEdit.replace(item.textEdit.insert, item.textEdit.newText);
|
||||
wranCapabilitiesNotSupported('textDocument.completion.completionItem.insertReplaceSupport');
|
||||
}
|
||||
return item;
|
||||
}
|
||||
function handleDefinitions(initializeParams, type, items) {
|
||||
const linkSupport = initializeParams.capabilities.textDocument?.[type]?.linkSupport ?? false;
|
||||
if (!linkSupport) {
|
||||
wranCapabilitiesNotSupported(`textDocument.${type}.linkSupport`);
|
||||
return items.map(item => ({
|
||||
uri: item.targetUri,
|
||||
range: item.targetRange,
|
||||
}));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
function wranCapabilitiesNotSupported(path) {
|
||||
if (reportedCapabilities.has(path)) {
|
||||
return;
|
||||
}
|
||||
reportedCapabilities.add(path);
|
||||
console.warn(`${path} is not supported by the client but could be used by the server.`);
|
||||
}
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
//# sourceMappingURL=languageFeatures.js.map
|
||||
12
node_modules/@volar/language-server/lib/features/textDocuments.d.ts
generated
vendored
Normal file
12
node_modules/@volar/language-server/lib/features/textDocuments.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as vscode from 'vscode-languageserver';
|
||||
import { URI } from 'vscode-uri';
|
||||
import { LanguageServerState } from '../types';
|
||||
import { SnapshotDocument } from '../utils/snapshotDocument';
|
||||
export declare function register(server: LanguageServerState): {
|
||||
all: () => SnapshotDocument[];
|
||||
onDidChangeContent: vscode.Event<vscode.TextDocumentChangeEvent<SnapshotDocument>>;
|
||||
onDidOpen: vscode.Event<vscode.TextDocumentChangeEvent<SnapshotDocument>>;
|
||||
onDidClose: vscode.Event<vscode.TextDocumentChangeEvent<SnapshotDocument>>;
|
||||
onDidSave: vscode.Event<vscode.TextDocumentChangeEvent<SnapshotDocument>>;
|
||||
get(uri: URI): SnapshotDocument | undefined;
|
||||
};
|
||||
54
node_modules/@volar/language-server/lib/features/textDocuments.js
generated
vendored
Normal file
54
node_modules/@volar/language-server/lib/features/textDocuments.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const vscode = require("vscode-languageserver");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const snapshotDocument_1 = require("../utils/snapshotDocument");
|
||||
function register(server) {
|
||||
const syncedDocumentParsedUriToUri = new Map();
|
||||
const documentsCache = new Map();
|
||||
const documents = new vscode.TextDocuments({
|
||||
create(uri, languageId, version, text) {
|
||||
const cache = documentsCache.get(uri)?.deref();
|
||||
if (cache && cache.languageId === languageId && cache.version === version && cache.getText() === text) {
|
||||
return cache;
|
||||
}
|
||||
const document = new snapshotDocument_1.SnapshotDocument(uri, languageId, version, text);
|
||||
documentsCache.set(uri, new WeakRef(document));
|
||||
return document;
|
||||
},
|
||||
update(snapshot, contentChanges, version) {
|
||||
snapshot.update(contentChanges, version);
|
||||
return snapshot;
|
||||
},
|
||||
});
|
||||
documents.listen(server.connection);
|
||||
documents.onDidOpen(({ document }) => {
|
||||
const parsedUri = vscode_uri_1.URI.parse(document.uri);
|
||||
syncedDocumentParsedUriToUri.set(parsedUri.toString(), document.uri);
|
||||
});
|
||||
documents.onDidClose(({ document }) => {
|
||||
const parsedUri = vscode_uri_1.URI.parse(document.uri);
|
||||
syncedDocumentParsedUriToUri.delete(parsedUri.toString());
|
||||
});
|
||||
server.onInitialize(serverCapabilities => {
|
||||
serverCapabilities.textDocumentSync = vscode.TextDocumentSyncKind.Incremental;
|
||||
});
|
||||
return {
|
||||
all: documents.all.bind(documents),
|
||||
onDidChangeContent: documents.onDidChangeContent.bind(documents),
|
||||
onDidOpen: documents.onDidOpen.bind(documents),
|
||||
onDidClose: documents.onDidClose.bind(documents),
|
||||
onDidSave: documents.onDidSave.bind(documents),
|
||||
get(uri) {
|
||||
return documents.get(getSyncedDocumentKey(uri) ?? uri.toString());
|
||||
},
|
||||
};
|
||||
function getSyncedDocumentKey(uri) {
|
||||
const originalUri = syncedDocumentParsedUriToUri.get(uri.toString());
|
||||
if (originalUri) {
|
||||
return originalUri;
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=textDocuments.js.map
|
||||
10
node_modules/@volar/language-server/lib/features/workspaceFolders.d.ts
generated
vendored
Normal file
10
node_modules/@volar/language-server/lib/features/workspaceFolders.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import * as vscode from 'vscode-languageserver';
|
||||
import { URI } from 'vscode-uri';
|
||||
import { LanguageServerState } from '../types';
|
||||
export declare function register(server: LanguageServerState): {
|
||||
readonly all: URI[];
|
||||
has(uri: URI): boolean;
|
||||
onDidChange: (cb: vscode.NotificationHandler<vscode.WorkspaceFoldersChangeEvent>) => {
|
||||
dispose(): void;
|
||||
};
|
||||
};
|
||||
67
node_modules/@volar/language-server/lib/features/workspaceFolders.js
generated
vendored
Normal file
67
node_modules/@volar/language-server/lib/features/workspaceFolders.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_service_1 = require("@volar/language-service");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
function register(server) {
|
||||
const folders = (0, language_service_1.createUriMap)();
|
||||
const didChangeCallbacks = new Set();
|
||||
server.onInitialize(serverCapabilities => {
|
||||
const { initializeParams } = server;
|
||||
if (initializeParams.workspaceFolders?.length) {
|
||||
for (const folder of initializeParams.workspaceFolders) {
|
||||
folders.set(vscode_uri_1.URI.parse(folder.uri), true);
|
||||
}
|
||||
}
|
||||
else if (initializeParams.rootUri) {
|
||||
folders.set(vscode_uri_1.URI.parse(initializeParams.rootUri), true);
|
||||
}
|
||||
else if (initializeParams.rootPath) {
|
||||
folders.set(vscode_uri_1.URI.file(initializeParams.rootPath), true);
|
||||
}
|
||||
// #18
|
||||
serverCapabilities.workspace ??= {};
|
||||
serverCapabilities.workspace.workspaceFolders = {
|
||||
supported: true,
|
||||
changeNotifications: true,
|
||||
};
|
||||
});
|
||||
server.onInitialized(() => {
|
||||
if (server.initializeParams.capabilities.workspace?.workspaceFolders) {
|
||||
server.connection.workspace.onDidChangeWorkspaceFolders(e => {
|
||||
e.added = e.added.filter(folder => !folders.has(vscode_uri_1.URI.parse(folder.uri)));
|
||||
e.removed = e.removed.filter(folder => folders.has(vscode_uri_1.URI.parse(folder.uri)));
|
||||
if (e.added.length || e.removed.length) {
|
||||
for (const folder of e.added) {
|
||||
folders.set(vscode_uri_1.URI.parse(folder.uri), true);
|
||||
}
|
||||
for (const folder of e.removed) {
|
||||
folders.delete(vscode_uri_1.URI.parse(folder.uri));
|
||||
}
|
||||
server.project.reload();
|
||||
for (const cb of didChangeCallbacks) {
|
||||
cb(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return {
|
||||
get all() {
|
||||
return [...folders.keys()];
|
||||
},
|
||||
has(uri) {
|
||||
return folders.has(uri);
|
||||
},
|
||||
onDidChange,
|
||||
};
|
||||
function onDidChange(cb) {
|
||||
didChangeCallbacks.add(cb);
|
||||
return {
|
||||
dispose() {
|
||||
didChangeCallbacks.delete(cb);
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=workspaceFolders.js.map
|
||||
6
node_modules/@volar/language-server/lib/fileSystemProviders/http.d.ts
generated
vendored
Normal file
6
node_modules/@volar/language-server/lib/fileSystemProviders/http.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { FileSystem } from '@volar/language-service';
|
||||
import type { URI } from 'vscode-uri';
|
||||
import { LanguageServer } from '../types';
|
||||
export declare const provider: FileSystem;
|
||||
export declare function listenEditorSettings(server: LanguageServer): void;
|
||||
export declare function handler(uri: URI): Promise<string | undefined>;
|
||||
46
node_modules/@volar/language-server/lib/fileSystemProviders/http.js
generated
vendored
Normal file
46
node_modules/@volar/language-server/lib/fileSystemProviders/http.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.provider = void 0;
|
||||
exports.listenEditorSettings = listenEditorSettings;
|
||||
exports.handler = handler;
|
||||
const language_service_1 = require("@volar/language-service");
|
||||
const request_light_1 = require("request-light");
|
||||
exports.provider = {
|
||||
async stat(uri) {
|
||||
const text = await this.readFile(uri);
|
||||
if (text !== undefined) {
|
||||
return {
|
||||
type: language_service_1.FileType.File,
|
||||
size: text.length,
|
||||
ctime: 0,
|
||||
mtime: 0,
|
||||
};
|
||||
}
|
||||
},
|
||||
readFile(uri) {
|
||||
return handler(uri);
|
||||
},
|
||||
readDirectory() {
|
||||
return [];
|
||||
},
|
||||
};
|
||||
function listenEditorSettings(server) {
|
||||
server.configurations.onDidChange(updateHttpSettings);
|
||||
updateHttpSettings();
|
||||
async function updateHttpSettings() {
|
||||
const httpSettings = await server.configurations.get('http');
|
||||
(0, request_light_1.configure)(httpSettings?.proxy, httpSettings?.proxyStrictSSL ?? false);
|
||||
}
|
||||
}
|
||||
function handler(uri) {
|
||||
const headers = { 'Accept-Encoding': 'gzip, deflate' };
|
||||
return (0, request_light_1.xhr)({ url: uri.toString(true), followRedirects: 5, headers }).then(response => {
|
||||
if (response.status !== 200) {
|
||||
return;
|
||||
}
|
||||
return response.responseText;
|
||||
}, (error) => {
|
||||
return Promise.reject(error.responseText || (0, request_light_1.getErrorStatusDescription)(error.status) || error.toString());
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=http.js.map
|
||||
2
node_modules/@volar/language-server/lib/fileSystemProviders/node.d.ts
generated
vendored
Normal file
2
node_modules/@volar/language-server/lib/fileSystemProviders/node.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { FileSystem } from '@volar/language-service';
|
||||
export declare const provider: FileSystem;
|
||||
49
node_modules/@volar/language-server/lib/fileSystemProviders/node.js
generated
vendored
Normal file
49
node_modules/@volar/language-server/lib/fileSystemProviders/node.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.provider = void 0;
|
||||
const language_service_1 = require("@volar/language-service");
|
||||
const fs = require("fs");
|
||||
exports.provider = {
|
||||
stat(uri) {
|
||||
try {
|
||||
const stats = fs.statSync(uri.fsPath, { throwIfNoEntry: false });
|
||||
if (stats) {
|
||||
return {
|
||||
type: stats.isFile() ? language_service_1.FileType.File
|
||||
: stats.isDirectory() ? language_service_1.FileType.Directory
|
||||
: stats.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
|
||||
: language_service_1.FileType.Unknown,
|
||||
ctime: stats.ctimeMs,
|
||||
mtime: stats.mtimeMs,
|
||||
size: stats.size,
|
||||
};
|
||||
}
|
||||
}
|
||||
catch {
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
readFile(uri, encoding) {
|
||||
try {
|
||||
return fs.readFileSync(uri.fsPath, { encoding: encoding ?? 'utf-8' });
|
||||
}
|
||||
catch {
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
readDirectory(uri) {
|
||||
try {
|
||||
const files = fs.readdirSync(uri.fsPath, { withFileTypes: true });
|
||||
return files.map(file => {
|
||||
return [file.name, file.isFile() ? language_service_1.FileType.File
|
||||
: file.isDirectory() ? language_service_1.FileType.Directory
|
||||
: file.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
|
||||
: language_service_1.FileType.Unknown];
|
||||
});
|
||||
}
|
||||
catch {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=node.js.map
|
||||
3
node_modules/@volar/language-server/lib/project/inferredCompilerOptions.d.ts
generated
vendored
Normal file
3
node_modules/@volar/language-server/lib/project/inferredCompilerOptions.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type * as ts from 'typescript';
|
||||
import type { LanguageServer } from '../types';
|
||||
export declare function getInferredCompilerOptions(server: LanguageServer): Promise<ts.CompilerOptions>;
|
||||
65
node_modules/@volar/language-server/lib/project/inferredCompilerOptions.js
generated
vendored
Normal file
65
node_modules/@volar/language-server/lib/project/inferredCompilerOptions.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getInferredCompilerOptions = getInferredCompilerOptions;
|
||||
async function getInferredCompilerOptions(server) {
|
||||
const [implicitProjectConfig_1 = {}, implicitProjectConfig_2 = {},] = await Promise.all([
|
||||
server.configurations.get('js/ts.implicitProjectConfig'),
|
||||
server.configurations.get('javascript.implicitProjectConfig'),
|
||||
]);
|
||||
const checkJs = readCheckJs();
|
||||
const experimentalDecorators = readExperimentalDecorators();
|
||||
const strictNullChecks = readImplicitStrictNullChecks();
|
||||
const strictFunctionTypes = readImplicitStrictFunctionTypes();
|
||||
const options = {
|
||||
...inferredProjectCompilerOptions('typescript'),
|
||||
allowJs: true,
|
||||
allowSyntheticDefaultImports: true,
|
||||
allowNonTsExtensions: true,
|
||||
resolveJsonModule: true,
|
||||
jsx: 1,
|
||||
};
|
||||
return options;
|
||||
function readCheckJs() {
|
||||
return implicitProjectConfig_1['checkJs']
|
||||
?? implicitProjectConfig_2['checkJs']
|
||||
?? false;
|
||||
}
|
||||
function readExperimentalDecorators() {
|
||||
return implicitProjectConfig_1['experimentalDecorators']
|
||||
?? implicitProjectConfig_2['experimentalDecorators']
|
||||
?? false;
|
||||
}
|
||||
function readImplicitStrictNullChecks() {
|
||||
return implicitProjectConfig_1['strictNullChecks'] ?? false;
|
||||
}
|
||||
function readImplicitStrictFunctionTypes() {
|
||||
return implicitProjectConfig_1['strictFunctionTypes'] ?? true;
|
||||
}
|
||||
function inferredProjectCompilerOptions(projectType) {
|
||||
const projectConfig = {
|
||||
module: 1,
|
||||
target: 7,
|
||||
jsx: 1,
|
||||
};
|
||||
if (checkJs) {
|
||||
projectConfig.checkJs = true;
|
||||
if (projectType === 'typescript') {
|
||||
projectConfig.allowJs = true;
|
||||
}
|
||||
}
|
||||
if (experimentalDecorators) {
|
||||
projectConfig.experimentalDecorators = true;
|
||||
}
|
||||
if (strictNullChecks) {
|
||||
projectConfig.strictNullChecks = true;
|
||||
}
|
||||
if (strictFunctionTypes) {
|
||||
projectConfig.strictFunctionTypes = true;
|
||||
}
|
||||
if (projectType === 'typescript') {
|
||||
projectConfig.sourceMap = true;
|
||||
}
|
||||
return projectConfig;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=inferredCompilerOptions.js.map
|
||||
5
node_modules/@volar/language-server/lib/project/simpleProject.d.ts
generated
vendored
Normal file
5
node_modules/@volar/language-server/lib/project/simpleProject.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { LanguagePlugin, LanguageServiceEnvironment } from '@volar/language-service';
|
||||
import type { URI } from 'vscode-uri';
|
||||
import type { LanguageServer, LanguageServerProject } from '../types';
|
||||
export declare function createSimpleProject(languagePlugins: LanguagePlugin<URI>[]): LanguageServerProject;
|
||||
export declare function createLanguageServiceEnvironment(server: LanguageServer, workspaceFolders: URI[]): LanguageServiceEnvironment;
|
||||
49
node_modules/@volar/language-server/lib/project/simpleProject.js
generated
vendored
Normal file
49
node_modules/@volar/language-server/lib/project/simpleProject.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createSimpleProject = createSimpleProject;
|
||||
exports.createLanguageServiceEnvironment = createLanguageServiceEnvironment;
|
||||
const language_service_1 = require("@volar/language-service");
|
||||
function createSimpleProject(languagePlugins) {
|
||||
let server;
|
||||
let languageService;
|
||||
return {
|
||||
setup(_server) {
|
||||
server = _server;
|
||||
const language = (0, language_service_1.createLanguage)([
|
||||
{ getLanguageId: uri => server.documents.get(uri)?.languageId },
|
||||
...languagePlugins,
|
||||
], (0, language_service_1.createUriMap)(false), uri => {
|
||||
const document = server.documents.get(uri);
|
||||
if (document) {
|
||||
language.scripts.set(uri, document.getSnapshot(), document.languageId);
|
||||
}
|
||||
else {
|
||||
language.scripts.delete(uri);
|
||||
}
|
||||
});
|
||||
languageService = (0, language_service_1.createLanguageService)(language, server.languageServicePlugins, createLanguageServiceEnvironment(server, server.workspaceFolders.all), {});
|
||||
},
|
||||
getLanguageService() {
|
||||
return languageService;
|
||||
},
|
||||
getExistingLanguageServices() {
|
||||
return [languageService];
|
||||
},
|
||||
reload() {
|
||||
languageService.dispose();
|
||||
this.setup(server);
|
||||
},
|
||||
};
|
||||
}
|
||||
function createLanguageServiceEnvironment(server, workspaceFolders) {
|
||||
return {
|
||||
workspaceFolders,
|
||||
fs: server.fileSystem,
|
||||
locale: server.initializeParams?.locale,
|
||||
clientCapabilities: server.initializeParams?.capabilities,
|
||||
getConfiguration: server.configurations.get,
|
||||
onDidChangeConfiguration: server.configurations.onDidChange,
|
||||
onDidChangeWatchedFiles: server.fileWatcher.onDidChangeWatchedFiles,
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=simpleProject.js.map
|
||||
22
node_modules/@volar/language-server/lib/project/typescriptProject.d.ts
generated
vendored
Normal file
22
node_modules/@volar/language-server/lib/project/typescriptProject.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Language, LanguagePlugin, ProjectContext, ProviderResult } from '@volar/language-service';
|
||||
import type * as ts from 'typescript';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServerProject } from '../types';
|
||||
import { ProjectExposeContext } from './typescriptProjectLs';
|
||||
export declare function createTypeScriptProject(ts: typeof import('typescript'), tsLocalized: ts.MapLike<string> | undefined, create: (projectContext: ProjectExposeContext) => ProviderResult<{
|
||||
languagePlugins: LanguagePlugin<URI>[];
|
||||
setup?(options: {
|
||||
language: Language;
|
||||
project: ProjectContext;
|
||||
}): void;
|
||||
}>): LanguageServerProject;
|
||||
export declare function createUriConverter(rootFolders: URI[]): {
|
||||
asFileName: (parsed: URI) => string;
|
||||
asUri: (fileName: string) => URI;
|
||||
};
|
||||
export declare function sortTSConfigs(file: string, a: string, b: string): number;
|
||||
export declare function isFileInDir(fileName: string, dir: string): boolean;
|
||||
export declare function getWorkspaceFolder(uri: URI, workspaceFolders: {
|
||||
has(uri: URI): boolean;
|
||||
all: URI[];
|
||||
}): URI;
|
||||
306
node_modules/@volar/language-server/lib/project/typescriptProject.js
generated
vendored
Normal file
306
node_modules/@volar/language-server/lib/project/typescriptProject.js
generated
vendored
Normal file
@@ -0,0 +1,306 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createTypeScriptProject = createTypeScriptProject;
|
||||
exports.createUriConverter = createUriConverter;
|
||||
exports.sortTSConfigs = sortTSConfigs;
|
||||
exports.isFileInDir = isFileInDir;
|
||||
exports.getWorkspaceFolder = getWorkspaceFolder;
|
||||
const language_service_1 = require("@volar/language-service");
|
||||
const path = require("path-browserify");
|
||||
const vscode = require("vscode-languageserver");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const inferredCompilerOptions_1 = require("./inferredCompilerOptions");
|
||||
const simpleProject_1 = require("./simpleProject");
|
||||
const typescriptProjectLs_1 = require("./typescriptProjectLs");
|
||||
const rootTsConfigNames = ['tsconfig.json', 'jsconfig.json'];
|
||||
function createTypeScriptProject(ts, tsLocalized, create) {
|
||||
let server;
|
||||
let uriConverter;
|
||||
const configProjects = (0, language_service_1.createUriMap)();
|
||||
const inferredProjects = (0, language_service_1.createUriMap)();
|
||||
const rootTsConfigs = new Set();
|
||||
const searchedDirs = new Set();
|
||||
return {
|
||||
setup(_server) {
|
||||
uriConverter = createUriConverter(_server.workspaceFolders.all);
|
||||
server = _server;
|
||||
server.fileWatcher.onDidChangeWatchedFiles(({ changes }) => {
|
||||
const tsConfigChanges = changes.filter(change => rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1)));
|
||||
for (const change of tsConfigChanges) {
|
||||
const changeUri = vscode_uri_1.URI.parse(change.uri);
|
||||
const changeFileName = uriConverter.asFileName(changeUri);
|
||||
if (change.type === vscode.FileChangeType.Created) {
|
||||
rootTsConfigs.add(changeFileName);
|
||||
}
|
||||
else if ((change.type === vscode.FileChangeType.Changed || change.type === vscode.FileChangeType.Deleted) && configProjects.has(changeUri)) {
|
||||
if (change.type === vscode.FileChangeType.Deleted) {
|
||||
rootTsConfigs.delete(changeFileName);
|
||||
}
|
||||
const project = configProjects.get(changeUri);
|
||||
configProjects.delete(changeUri);
|
||||
project?.then(project => project.dispose());
|
||||
}
|
||||
}
|
||||
server.languageFeatures.requestRefresh(!!tsConfigChanges.length);
|
||||
});
|
||||
},
|
||||
async getLanguageService(uri) {
|
||||
const tsconfig = await findMatchTSConfig(server, uri);
|
||||
if (tsconfig) {
|
||||
const project = await getOrCreateConfiguredProject(server, tsconfig);
|
||||
return project.languageService;
|
||||
}
|
||||
const workspaceFolder = getWorkspaceFolder(uri, server.workspaceFolders);
|
||||
const project = await getOrCreateInferredProject(server, uri, workspaceFolder);
|
||||
return project.languageService;
|
||||
},
|
||||
async getExistingLanguageServices() {
|
||||
const projects = await Promise.all([
|
||||
...configProjects.values() ?? [],
|
||||
...inferredProjects.values() ?? [],
|
||||
]);
|
||||
return projects.map(project => project.languageService);
|
||||
},
|
||||
reload() {
|
||||
for (const project of [
|
||||
...configProjects.values() ?? [],
|
||||
...inferredProjects.values() ?? [],
|
||||
]) {
|
||||
project.then(p => p.dispose());
|
||||
}
|
||||
configProjects.clear();
|
||||
inferredProjects.clear();
|
||||
},
|
||||
};
|
||||
async function findMatchTSConfig(server, uri) {
|
||||
const fileName = uriConverter.asFileName(uri);
|
||||
let dir = path.dirname(fileName);
|
||||
while (true) {
|
||||
if (searchedDirs.has(dir)) {
|
||||
break;
|
||||
}
|
||||
searchedDirs.add(dir);
|
||||
for (const tsConfigName of rootTsConfigNames) {
|
||||
const tsconfigPath = path.join(dir, tsConfigName);
|
||||
if ((await server.fileSystem.stat?.(uriConverter.asUri(tsconfigPath)))?.type === language_service_1.FileType.File) {
|
||||
rootTsConfigs.add(tsconfigPath);
|
||||
}
|
||||
}
|
||||
dir = path.dirname(dir);
|
||||
}
|
||||
await prepareClosestootCommandLine();
|
||||
return await findDirectIncludeTsconfig() ?? await findIndirectReferenceTsconfig();
|
||||
async function prepareClosestootCommandLine() {
|
||||
let matches = [];
|
||||
for (const rootTsConfig of rootTsConfigs) {
|
||||
if (isFileInDir(fileName, path.dirname(rootTsConfig))) {
|
||||
matches.push(rootTsConfig);
|
||||
}
|
||||
}
|
||||
matches = matches.sort((a, b) => sortTSConfigs(fileName, a, b));
|
||||
if (matches.length) {
|
||||
await getCommandLine(matches[0]);
|
||||
}
|
||||
}
|
||||
function findIndirectReferenceTsconfig() {
|
||||
return findTSConfig(async (tsconfig) => {
|
||||
const tsconfigUri = uriConverter.asUri(tsconfig);
|
||||
const project = await configProjects.get(tsconfigUri);
|
||||
const languageService = project?.languageService.context.inject('typescript/languageService');
|
||||
return !!languageService?.getProgram()?.getSourceFile(fileName);
|
||||
});
|
||||
}
|
||||
function findDirectIncludeTsconfig() {
|
||||
return findTSConfig(async (tsconfig) => {
|
||||
const map = (0, language_service_1.createUriMap)();
|
||||
const commandLine = await getCommandLine(tsconfig);
|
||||
for (const fileName of commandLine?.fileNames ?? []) {
|
||||
const uri = uriConverter.asUri(fileName);
|
||||
map.set(uri, true);
|
||||
}
|
||||
return map.has(uri);
|
||||
});
|
||||
}
|
||||
async function findTSConfig(match) {
|
||||
const checked = new Set();
|
||||
for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTSConfigs(fileName, a, b))) {
|
||||
const tsconfigUri = uriConverter.asUri(rootTsConfig);
|
||||
const project = await configProjects.get(tsconfigUri);
|
||||
if (project) {
|
||||
let chains = await getReferencesChains(project.getCommandLine(), rootTsConfig, []);
|
||||
// This is to be consistent with tsserver behavior
|
||||
chains = chains.reverse();
|
||||
for (const chain of chains) {
|
||||
for (let i = chain.length - 1; i >= 0; i--) {
|
||||
const tsconfig = chain[i];
|
||||
if (checked.has(tsconfig)) {
|
||||
continue;
|
||||
}
|
||||
checked.add(tsconfig);
|
||||
if (await match(tsconfig)) {
|
||||
return tsconfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
async function getReferencesChains(commandLine, tsConfig, before) {
|
||||
if (commandLine.projectReferences?.length) {
|
||||
const newChains = [];
|
||||
for (const projectReference of commandLine.projectReferences) {
|
||||
let tsConfigPath = projectReference.path.replace(/\\/g, '/');
|
||||
// fix https://github.com/johnsoncodehk/volar/issues/712
|
||||
if ((await server.fileSystem.stat?.(uriConverter.asUri(tsConfigPath)))?.type === language_service_1.FileType.File) {
|
||||
const newTsConfigPath = path.join(tsConfigPath, 'tsconfig.json');
|
||||
const newJsConfigPath = path.join(tsConfigPath, 'jsconfig.json');
|
||||
if ((await server.fileSystem.stat?.(uriConverter.asUri(newTsConfigPath)))?.type === language_service_1.FileType.File) {
|
||||
tsConfigPath = newTsConfigPath;
|
||||
}
|
||||
else if ((await server.fileSystem.stat?.(uriConverter.asUri(newJsConfigPath)))?.type === language_service_1.FileType.File) {
|
||||
tsConfigPath = newJsConfigPath;
|
||||
}
|
||||
}
|
||||
const beforeIndex = before.indexOf(tsConfigPath); // cycle
|
||||
if (beforeIndex >= 0) {
|
||||
newChains.push(before.slice(0, Math.max(beforeIndex, 1)));
|
||||
}
|
||||
else {
|
||||
const referenceCommandLine = await getCommandLine(tsConfigPath);
|
||||
if (referenceCommandLine) {
|
||||
for (const chain of await getReferencesChains(referenceCommandLine, tsConfigPath, [...before, tsConfig])) {
|
||||
newChains.push(chain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return newChains;
|
||||
}
|
||||
else {
|
||||
return [[...before, tsConfig]];
|
||||
}
|
||||
}
|
||||
async function getCommandLine(tsConfig) {
|
||||
const project = await getOrCreateConfiguredProject(server, tsConfig);
|
||||
return project?.getCommandLine();
|
||||
}
|
||||
}
|
||||
function getOrCreateConfiguredProject(server, tsconfig) {
|
||||
tsconfig = tsconfig.replace(/\\/g, '/');
|
||||
const tsconfigUri = uriConverter.asUri(tsconfig);
|
||||
let projectPromise = configProjects.get(tsconfigUri);
|
||||
if (!projectPromise) {
|
||||
const workspaceFolder = getWorkspaceFolder(tsconfigUri, server.workspaceFolders);
|
||||
const serviceEnv = (0, simpleProject_1.createLanguageServiceEnvironment)(server, [workspaceFolder]);
|
||||
projectPromise = (0, typescriptProjectLs_1.createTypeScriptLS)(ts, tsLocalized, tsconfig, server, serviceEnv, workspaceFolder, uriConverter, create);
|
||||
configProjects.set(tsconfigUri, projectPromise);
|
||||
}
|
||||
return projectPromise;
|
||||
}
|
||||
async function getOrCreateInferredProject(server, uri, workspaceFolder) {
|
||||
if (!inferredProjects.has(workspaceFolder)) {
|
||||
inferredProjects.set(workspaceFolder, (async () => {
|
||||
const inferOptions = await (0, inferredCompilerOptions_1.getInferredCompilerOptions)(server);
|
||||
const serviceEnv = (0, simpleProject_1.createLanguageServiceEnvironment)(server, [workspaceFolder]);
|
||||
return (0, typescriptProjectLs_1.createTypeScriptLS)(ts, tsLocalized, inferOptions, server, serviceEnv, workspaceFolder, uriConverter, create);
|
||||
})());
|
||||
}
|
||||
const project = await inferredProjects.get(workspaceFolder);
|
||||
project.tryAddFile(uriConverter.asFileName(uri));
|
||||
return project;
|
||||
}
|
||||
}
|
||||
function createUriConverter(rootFolders) {
|
||||
const encodeds = new Map();
|
||||
const isFileScheme = rootFolders.every(folder => folder.scheme === 'file');
|
||||
return {
|
||||
asFileName,
|
||||
asUri,
|
||||
};
|
||||
function asFileName(parsed) {
|
||||
if (rootFolders.every(folder => folder.scheme === parsed.scheme && folder.authority === parsed.authority)) {
|
||||
if (isFileScheme) {
|
||||
return parsed.fsPath.replace(/\\/g, '/');
|
||||
}
|
||||
else {
|
||||
return parsed.path;
|
||||
}
|
||||
}
|
||||
const encoded = encodeURIComponent(`${parsed.scheme}://${parsed.authority}`);
|
||||
encodeds.set(encoded, parsed);
|
||||
return `/${encoded}${parsed.path}`;
|
||||
}
|
||||
function asUri(fileName) {
|
||||
for (const [encoded, uri] of encodeds) {
|
||||
const prefix = `/${encoded}`;
|
||||
if (fileName === prefix) {
|
||||
return vscode_uri_1.URI.from({
|
||||
scheme: uri.scheme,
|
||||
authority: uri.authority,
|
||||
});
|
||||
}
|
||||
if (uri.authority) {
|
||||
if (fileName.startsWith(prefix + '/')) {
|
||||
return vscode_uri_1.URI.from({
|
||||
scheme: uri.scheme,
|
||||
authority: uri.authority,
|
||||
path: fileName.substring(prefix.length),
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (fileName.startsWith(prefix)) {
|
||||
return vscode_uri_1.URI.from({
|
||||
scheme: uri.scheme,
|
||||
authority: uri.authority,
|
||||
path: fileName.substring(prefix.length),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isFileScheme) {
|
||||
for (const folder of rootFolders) {
|
||||
return vscode_uri_1.URI.parse(`${folder.scheme}://${folder.authority}${fileName}`);
|
||||
}
|
||||
}
|
||||
return vscode_uri_1.URI.file(fileName);
|
||||
}
|
||||
}
|
||||
function sortTSConfigs(file, a, b) {
|
||||
const inA = isFileInDir(file, path.dirname(a));
|
||||
const inB = isFileInDir(file, path.dirname(b));
|
||||
if (inA !== inB) {
|
||||
const aWeight = inA ? 1 : 0;
|
||||
const bWeight = inB ? 1 : 0;
|
||||
return bWeight - aWeight;
|
||||
}
|
||||
const aLength = a.split('/').length;
|
||||
const bLength = b.split('/').length;
|
||||
if (aLength === bLength) {
|
||||
const aWeight = path.basename(a) === 'tsconfig.json' ? 1 : 0;
|
||||
const bWeight = path.basename(b) === 'tsconfig.json' ? 1 : 0;
|
||||
return bWeight - aWeight;
|
||||
}
|
||||
return bLength - aLength;
|
||||
}
|
||||
function isFileInDir(fileName, dir) {
|
||||
const relative = path.relative(dir, fileName);
|
||||
return !!relative && !relative.startsWith('..') && !path.isAbsolute(relative);
|
||||
}
|
||||
function getWorkspaceFolder(uri, workspaceFolders) {
|
||||
while (true) {
|
||||
if (workspaceFolders.has(uri)) {
|
||||
return uri;
|
||||
}
|
||||
const next = uri.with({ path: uri.path.substring(0, uri.path.lastIndexOf('/')) });
|
||||
if (next.path === uri.path) {
|
||||
break;
|
||||
}
|
||||
uri = next;
|
||||
}
|
||||
for (const folder of workspaceFolders.all) {
|
||||
return folder;
|
||||
}
|
||||
return uri.with({ path: '/' });
|
||||
}
|
||||
//# sourceMappingURL=typescriptProject.js.map
|
||||
31
node_modules/@volar/language-server/lib/project/typescriptProjectLs.d.ts
generated
vendored
Normal file
31
node_modules/@volar/language-server/lib/project/typescriptProjectLs.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Language, LanguagePlugin, LanguageService, LanguageServiceEnvironment, ProjectContext, ProviderResult } from '@volar/language-service';
|
||||
import { TypeScriptProjectHost, createSys } from '@volar/typescript';
|
||||
import type * as ts from 'typescript';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServer } from '../types';
|
||||
export interface TypeScriptProjectLS {
|
||||
tryAddFile(fileName: string): void;
|
||||
getCommandLine(): ts.ParsedCommandLine;
|
||||
languageService: LanguageService;
|
||||
dispose(): void;
|
||||
}
|
||||
export interface ProjectExposeContext {
|
||||
env: LanguageServiceEnvironment;
|
||||
configFileName: string | undefined;
|
||||
projectHost: TypeScriptProjectHost;
|
||||
sys: ReturnType<typeof createSys>;
|
||||
uriConverter: {
|
||||
asUri(fileName: string): URI;
|
||||
asFileName(uri: URI): string;
|
||||
};
|
||||
}
|
||||
export declare function createTypeScriptLS(ts: typeof import('typescript'), tsLocalized: ts.MapLike<string> | undefined, tsconfig: string | ts.CompilerOptions, server: LanguageServer, serviceEnv: LanguageServiceEnvironment, workspaceFolder: URI, uriConverter: {
|
||||
asUri(fileName: string): URI;
|
||||
asFileName(uri: URI): string;
|
||||
}, create: (projectContext: ProjectExposeContext) => ProviderResult<{
|
||||
languagePlugins: LanguagePlugin<URI>[];
|
||||
setup?(options: {
|
||||
language: Language;
|
||||
project: ProjectContext;
|
||||
}): void;
|
||||
}>): Promise<TypeScriptProjectLS>;
|
||||
232
node_modules/@volar/language-server/lib/project/typescriptProjectLs.js
generated
vendored
Normal file
232
node_modules/@volar/language-server/lib/project/typescriptProjectLs.js
generated
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createTypeScriptLS = createTypeScriptLS;
|
||||
const language_service_1 = require("@volar/language-service");
|
||||
const typescript_1 = require("@volar/typescript");
|
||||
const utilities_1 = require("@volar/typescript/lib/typescript/utilities");
|
||||
const path = require("path-browserify");
|
||||
const vscode = require("vscode-languageserver");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const fsFileSnapshots = (0, language_service_1.createUriMap)();
|
||||
async function createTypeScriptLS(ts, tsLocalized, tsconfig, server, serviceEnv, workspaceFolder, uriConverter, create) {
|
||||
let commandLine;
|
||||
let projectVersion = 0;
|
||||
const getCurrentDirectory = () => uriConverter.asFileName(workspaceFolder);
|
||||
const sys = (0, typescript_1.createSys)(ts.sys, serviceEnv, getCurrentDirectory, uriConverter);
|
||||
const projectHost = {
|
||||
getCurrentDirectory,
|
||||
getProjectVersion() {
|
||||
return projectVersion.toString();
|
||||
},
|
||||
getScriptFileNames() {
|
||||
return commandLine.fileNames;
|
||||
},
|
||||
getCompilationSettings() {
|
||||
return commandLine.options;
|
||||
},
|
||||
getLocalizedDiagnosticMessages: tsLocalized ? () => tsLocalized : undefined,
|
||||
getProjectReferences() {
|
||||
return commandLine.projectReferences;
|
||||
},
|
||||
};
|
||||
const { languagePlugins, setup } = await create({
|
||||
env: serviceEnv,
|
||||
configFileName: typeof tsconfig === 'string' ? tsconfig : undefined,
|
||||
projectHost,
|
||||
sys,
|
||||
uriConverter,
|
||||
});
|
||||
const unsavedRootFileUris = (0, language_service_1.createUriMap)();
|
||||
const disposables = [
|
||||
server.documents.onDidOpen(({ document }) => updateFsCacheFromSyncedDocument(document)),
|
||||
server.documents.onDidSave(({ document }) => updateFsCacheFromSyncedDocument(document)),
|
||||
server.documents.onDidChangeContent(() => projectVersion++),
|
||||
serviceEnv.onDidChangeWatchedFiles?.(async ({ changes }) => {
|
||||
const createdOrDeleted = changes.some(change => change.type !== vscode.FileChangeType.Changed);
|
||||
if (createdOrDeleted) {
|
||||
await updateCommandLine();
|
||||
}
|
||||
projectVersion++;
|
||||
}),
|
||||
server.documents.onDidOpen(async ({ document }) => {
|
||||
const uri = vscode_uri_1.URI.parse(document.uri);
|
||||
const isWorkspaceFile = workspaceFolder.scheme === uri.scheme;
|
||||
if (!isWorkspaceFile) {
|
||||
return;
|
||||
}
|
||||
const stat = await serviceEnv.fs?.stat(uri);
|
||||
const isUnsaved = stat?.type !== 1;
|
||||
if (isUnsaved) {
|
||||
const lastProjectVersion = projectVersion;
|
||||
await updateCommandLine();
|
||||
if (lastProjectVersion !== projectVersion) {
|
||||
unsavedRootFileUris.set(uri, true);
|
||||
}
|
||||
}
|
||||
}),
|
||||
server.documents.onDidClose(async ({ document }) => {
|
||||
const uri = vscode_uri_1.URI.parse(document.uri);
|
||||
if (unsavedRootFileUris.has(uri)) {
|
||||
unsavedRootFileUris.delete(uri);
|
||||
await updateCommandLine();
|
||||
}
|
||||
}),
|
||||
].filter(d => !!d);
|
||||
await updateCommandLine();
|
||||
const language = (0, language_service_1.createLanguage)([
|
||||
{ getLanguageId: uri => server.documents.get(uri)?.languageId },
|
||||
...languagePlugins,
|
||||
{ getLanguageId: uri => (0, typescript_1.resolveFileLanguageId)(uri.path) },
|
||||
], (0, language_service_1.createUriMap)(sys.useCaseSensitiveFileNames), (uri, includeFsFiles) => {
|
||||
const syncedDocument = server.documents.get(uri);
|
||||
let snapshot;
|
||||
if (syncedDocument) {
|
||||
snapshot = syncedDocument.getSnapshot();
|
||||
}
|
||||
else if (includeFsFiles) {
|
||||
const cache = fsFileSnapshots.get(uri);
|
||||
const fileName = uriConverter.asFileName(uri);
|
||||
const modifiedTime = sys.getModifiedTime?.(fileName)?.valueOf();
|
||||
if (!cache || cache[0] !== modifiedTime) {
|
||||
if (sys.fileExists(fileName)) {
|
||||
const text = sys.readFile(fileName);
|
||||
const snapshot = text !== undefined ? ts.ScriptSnapshot.fromString(text) : undefined;
|
||||
fsFileSnapshots.set(uri, [modifiedTime, snapshot]);
|
||||
}
|
||||
else {
|
||||
fsFileSnapshots.set(uri, [modifiedTime, undefined]);
|
||||
}
|
||||
}
|
||||
snapshot = fsFileSnapshots.get(uri)?.[1];
|
||||
}
|
||||
if (snapshot) {
|
||||
language.scripts.set(uri, snapshot);
|
||||
}
|
||||
else {
|
||||
language.scripts.delete(uri);
|
||||
}
|
||||
});
|
||||
const project = {
|
||||
typescript: {
|
||||
configFileName: typeof tsconfig === 'string' ? tsconfig : undefined,
|
||||
sys,
|
||||
uriConverter,
|
||||
...(0, typescript_1.createLanguageServiceHost)(ts, sys, language, s => uriConverter.asUri(s), projectHost),
|
||||
},
|
||||
};
|
||||
setup?.({ language, project });
|
||||
const languageService = (0, language_service_1.createLanguageService)(language, server.languageServicePlugins, serviceEnv, project);
|
||||
return {
|
||||
languageService,
|
||||
tryAddFile(fileName) {
|
||||
if (!commandLine.fileNames.includes(fileName)) {
|
||||
commandLine.fileNames.push(fileName);
|
||||
projectVersion++;
|
||||
}
|
||||
},
|
||||
dispose: () => {
|
||||
sys.dispose();
|
||||
languageService?.dispose();
|
||||
disposables.forEach(({ dispose }) => dispose());
|
||||
disposables.length = 0;
|
||||
},
|
||||
getCommandLine: () => commandLine,
|
||||
};
|
||||
function updateFsCacheFromSyncedDocument(document) {
|
||||
const uri = vscode_uri_1.URI.parse(document.uri);
|
||||
const fileName = uriConverter.asFileName(uri);
|
||||
if (fsFileSnapshots.has(uri) || sys.fileExists(fileName)) {
|
||||
const modifiedTime = sys.getModifiedTime?.(fileName);
|
||||
fsFileSnapshots.set(uri, [modifiedTime?.valueOf(), document.getSnapshot()]);
|
||||
}
|
||||
}
|
||||
async function updateCommandLine() {
|
||||
const oldFileNames = new Set(commandLine?.fileNames ?? []);
|
||||
commandLine = await parseConfig(ts, sys, uriConverter.asFileName(workspaceFolder), tsconfig, languagePlugins.map(plugin => plugin.typescript?.extraFileExtensions ?? []).flat());
|
||||
const newFileNames = new Set(commandLine.fileNames);
|
||||
if (oldFileNames.size !== newFileNames.size || [...oldFileNames].some(fileName => !newFileNames.has(fileName))) {
|
||||
projectVersion++;
|
||||
}
|
||||
}
|
||||
async function parseConfig(ts, sys, workspacePath, tsconfig, extraFileExtensions) {
|
||||
let commandLine = {
|
||||
errors: [],
|
||||
fileNames: [],
|
||||
options: {},
|
||||
};
|
||||
let sysVersion;
|
||||
let newSysVersion = await sys.sync();
|
||||
while (sysVersion !== newSysVersion) {
|
||||
sysVersion = newSysVersion;
|
||||
try {
|
||||
commandLine = await parseConfigWorker(ts, sys, workspacePath, tsconfig, extraFileExtensions);
|
||||
}
|
||||
catch {
|
||||
// will be failed if web fs host first result not ready
|
||||
}
|
||||
newSysVersion = await sys.sync();
|
||||
}
|
||||
return commandLine;
|
||||
}
|
||||
function parseConfigWorker(ts, _host, workspacePath, tsconfig, extraFileExtensions) {
|
||||
let content = {
|
||||
errors: [],
|
||||
fileNames: [],
|
||||
options: {},
|
||||
};
|
||||
const maybeUnsavedFileNames = server.documents.all()
|
||||
.map(document => vscode_uri_1.URI.parse(document.uri))
|
||||
.filter(uri => uri.scheme === workspaceFolder.scheme)
|
||||
.map(uri => uriConverter.asFileName(uri));
|
||||
const host = {
|
||||
..._host,
|
||||
readDirectory(rootDir, extensions, excludes, includes, depth) {
|
||||
const fsFiles = _host.readDirectory(rootDir, extensions, excludes, includes, depth);
|
||||
const unsavedFiles = (0, utilities_1.matchFiles)(rootDir, extensions, excludes, includes, sys.useCaseSensitiveFileNames, getCurrentDirectory(), depth, dirPath => {
|
||||
dirPath = dirPath.replace(/\\/g, '/');
|
||||
const files = [];
|
||||
const dirs = [];
|
||||
for (const fileName of maybeUnsavedFileNames) {
|
||||
const match = sys.useCaseSensitiveFileNames
|
||||
? fileName.startsWith(dirPath + '/')
|
||||
: fileName.toLowerCase().startsWith(dirPath.toLowerCase() + '/');
|
||||
if (match) {
|
||||
const name = fileName.slice(dirPath.length + 1);
|
||||
if (name.includes('/')) {
|
||||
const dir = name.split('/')[0];
|
||||
if (!dirs.includes(dir)) {
|
||||
dirs.push(dir);
|
||||
}
|
||||
}
|
||||
else {
|
||||
files.push(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
files,
|
||||
directories: dirs,
|
||||
};
|
||||
}, path => path);
|
||||
if (!unsavedFiles.length) {
|
||||
return fsFiles;
|
||||
}
|
||||
return [...new Set([...fsFiles, ...unsavedFiles])];
|
||||
},
|
||||
};
|
||||
if (typeof tsconfig === 'string') {
|
||||
const config = ts.readJsonConfigFile(tsconfig, host.readFile);
|
||||
content = ts.parseJsonSourceFileConfigFileContent(config, host, path.dirname(tsconfig), {}, tsconfig, undefined, extraFileExtensions);
|
||||
}
|
||||
else {
|
||||
content = ts.parseJsonConfigFileContent({ files: [] }, host, workspacePath, tsconfig, workspacePath + '/jsconfig.json', undefined, extraFileExtensions);
|
||||
}
|
||||
// fix https://github.com/johnsoncodehk/volar/issues/1786
|
||||
// https://github.com/microsoft/TypeScript/issues/30457
|
||||
// patching ts server broke with outDir + rootDir + composite/incremental
|
||||
content.options.outDir = undefined;
|
||||
content.fileNames = content.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
|
||||
return content;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=typescriptProjectLs.js.map
|
||||
52
node_modules/@volar/language-server/lib/server.d.ts
generated
vendored
Normal file
52
node_modules/@volar/language-server/lib/server.d.ts
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
import { LanguageServicePlugin } from '@volar/language-service';
|
||||
import * as vscode from 'vscode-languageserver';
|
||||
import type { ExperimentalFeatures, LanguageServerEnvironment, LanguageServerProject } from './types.js';
|
||||
export declare function createServerBase(connection: vscode.Connection, env: LanguageServerEnvironment): {
|
||||
initializeParams: vscode.InitializeParams;
|
||||
project: LanguageServerProject;
|
||||
languageServicePlugins: LanguageServicePlugin<any>[];
|
||||
initialize(params: vscode.InitializeParams, project: LanguageServerProject, languageServicePlugins: LanguageServicePlugin[]): vscode.InitializeResult<ExperimentalFeatures>;
|
||||
initialized(): void;
|
||||
shutdown(): void;
|
||||
configurations: {
|
||||
get: <T>(section: string, scopeUri?: string) => Promise<T | undefined>;
|
||||
onDidChange: (cb: vscode.NotificationHandler<vscode.DidChangeConfigurationParams>) => {
|
||||
dispose(): void;
|
||||
};
|
||||
};
|
||||
editorFeatures: void;
|
||||
documents: {
|
||||
all: () => import("./utils/snapshotDocument.js").SnapshotDocument[];
|
||||
onDidChangeContent: vscode.Event<vscode.TextDocumentChangeEvent<import("./utils/snapshotDocument.js").SnapshotDocument>>;
|
||||
onDidOpen: vscode.Event<vscode.TextDocumentChangeEvent<import("./utils/snapshotDocument.js").SnapshotDocument>>;
|
||||
onDidClose: vscode.Event<vscode.TextDocumentChangeEvent<import("./utils/snapshotDocument.js").SnapshotDocument>>;
|
||||
onDidSave: vscode.Event<vscode.TextDocumentChangeEvent<import("./utils/snapshotDocument.js").SnapshotDocument>>;
|
||||
get(uri: import("vscode-uri").URI): import("./utils/snapshotDocument.js").SnapshotDocument | undefined;
|
||||
};
|
||||
workspaceFolders: {
|
||||
readonly all: import("vscode-uri").URI[];
|
||||
has(uri: import("vscode-uri").URI): boolean;
|
||||
onDidChange: (cb: vscode.NotificationHandler<vscode.WorkspaceFoldersChangeEvent>) => {
|
||||
dispose(): void;
|
||||
};
|
||||
};
|
||||
fileWatcher: {
|
||||
watchFiles: (patterns: string[]) => Promise<vscode.Disposable>;
|
||||
onDidChangeWatchedFiles: (cb: vscode.NotificationHandler<vscode.DidChangeWatchedFilesParams>) => {
|
||||
dispose: () => void;
|
||||
};
|
||||
};
|
||||
languageFeatures: {
|
||||
requestRefresh: (clearDiagnostics: boolean) => Promise<void>;
|
||||
};
|
||||
fileSystem: {
|
||||
readFile(uri: import("vscode-uri").URI): string | Thenable<string | undefined>;
|
||||
stat(uri: import("vscode-uri").URI): import("@volar/language-service").FileStat | Thenable<import("@volar/language-service").FileStat | undefined>;
|
||||
readDirectory(uri: import("vscode-uri").URI): import("@volar/language-service").ProviderResult<[string, import("@volar/language-service").FileType][]>;
|
||||
install(scheme: string, provider: import("@volar/language-service").FileSystem): void;
|
||||
};
|
||||
env: LanguageServerEnvironment;
|
||||
connection: vscode.Connection;
|
||||
onInitialize(callback: (serverCapabilities: vscode.ServerCapabilities<ExperimentalFeatures>) => void): void;
|
||||
onInitialized(callback: () => void): void;
|
||||
};
|
||||
70
node_modules/@volar/language-server/lib/server.js
generated
vendored
Normal file
70
node_modules/@volar/language-server/lib/server.js
generated
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createServerBase = createServerBase;
|
||||
const configurations_js_1 = require("./features/configurations.js");
|
||||
const editorFeatures_js_1 = require("./features/editorFeatures.js");
|
||||
const fileSystem_js_1 = require("./features/fileSystem.js");
|
||||
const fileWatcher_js_1 = require("./features/fileWatcher.js");
|
||||
const languageFeatures_js_1 = require("./features/languageFeatures.js");
|
||||
const textDocuments_js_1 = require("./features/textDocuments.js");
|
||||
const workspaceFolders_js_1 = require("./features/workspaceFolders.js");
|
||||
function createServerBase(connection, env) {
|
||||
const onInitializeCallbacks = [];
|
||||
const onInitializedCallbacks = [];
|
||||
const state = {
|
||||
env,
|
||||
connection,
|
||||
initializeParams: undefined,
|
||||
project: undefined,
|
||||
languageServicePlugins: undefined,
|
||||
onInitialize(callback) {
|
||||
onInitializeCallbacks.push(callback);
|
||||
},
|
||||
onInitialized(callback) {
|
||||
onInitializedCallbacks.push(callback);
|
||||
},
|
||||
};
|
||||
const configurations = (0, configurations_js_1.register)(state);
|
||||
const editorFeatures = (0, editorFeatures_js_1.register)(state);
|
||||
const documents = (0, textDocuments_js_1.register)(state);
|
||||
const workspaceFolders = (0, workspaceFolders_js_1.register)(state);
|
||||
const fileWatcher = (0, fileWatcher_js_1.register)(state);
|
||||
const languageFeatures = (0, languageFeatures_js_1.register)(state, documents, configurations);
|
||||
const fileSystem = (0, fileSystem_js_1.register)(documents, fileWatcher);
|
||||
const server = {
|
||||
...state,
|
||||
get initializeParams() {
|
||||
return state.initializeParams;
|
||||
},
|
||||
get project() {
|
||||
return state.project;
|
||||
},
|
||||
get languageServicePlugins() {
|
||||
return state.languageServicePlugins;
|
||||
},
|
||||
initialize(params, project, languageServicePlugins) {
|
||||
state.initializeParams = params;
|
||||
state.project = project;
|
||||
state.languageServicePlugins = languageServicePlugins;
|
||||
const serverCapabilities = {};
|
||||
onInitializeCallbacks.forEach(cb => cb(serverCapabilities));
|
||||
return { capabilities: serverCapabilities };
|
||||
},
|
||||
initialized() {
|
||||
onInitializedCallbacks.forEach(cb => cb());
|
||||
state.project.setup(server);
|
||||
},
|
||||
shutdown() {
|
||||
state.project.reload();
|
||||
},
|
||||
configurations,
|
||||
editorFeatures,
|
||||
documents,
|
||||
workspaceFolders,
|
||||
fileWatcher,
|
||||
languageFeatures,
|
||||
fileSystem,
|
||||
};
|
||||
return server;
|
||||
}
|
||||
//# sourceMappingURL=server.js.map
|
||||
34
node_modules/@volar/language-server/lib/types.d.ts
generated
vendored
Normal file
34
node_modules/@volar/language-server/lib/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { InitializeParams, LanguageService, LanguageServicePlugin, ProviderResult, ServerCapabilities } from '@volar/language-service';
|
||||
import { Connection } from 'vscode-languageserver';
|
||||
import type { URI } from 'vscode-uri';
|
||||
import { createServerBase } from './server';
|
||||
export interface LanguageServerEnvironment {
|
||||
timer: {
|
||||
setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => void;
|
||||
};
|
||||
}
|
||||
export interface LanguageServerProject {
|
||||
setup(server: LanguageServer): void;
|
||||
getLanguageService(uri: URI): ProviderResult<LanguageService>;
|
||||
getExistingLanguageServices(): ProviderResult<LanguageService[]>;
|
||||
reload(): void;
|
||||
}
|
||||
export interface LanguageServerState {
|
||||
env: LanguageServerEnvironment;
|
||||
connection: Connection;
|
||||
initializeParams: InitializeParams;
|
||||
project: LanguageServerProject;
|
||||
languageServicePlugins: LanguageServicePlugin[];
|
||||
onInitialize(callback: (serverCapabilities: ServerCapabilities<ExperimentalFeatures>) => void): void;
|
||||
onInitialized(callback: () => void): void;
|
||||
}
|
||||
export type LanguageServer = ReturnType<typeof createServerBase>;
|
||||
export interface ExperimentalFeatures {
|
||||
fileReferencesProvider?: boolean;
|
||||
fileRenameEditsProvider?: boolean;
|
||||
documentDropEditsProvider?: boolean;
|
||||
autoInsertionProvider?: {
|
||||
triggerCharacters: string[];
|
||||
configurationSections?: (string[] | null)[];
|
||||
};
|
||||
}
|
||||
3
node_modules/@volar/language-server/lib/types.js
generated
vendored
Normal file
3
node_modules/@volar/language-server/lib/types.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=types.js.map
|
||||
2
node_modules/@volar/language-server/lib/utils/combineChangeRanges.d.ts
generated
vendored
Normal file
2
node_modules/@volar/language-server/lib/utils/combineChangeRanges.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type * as ts from 'typescript';
|
||||
export declare function combineChangeRanges(...changeRanges: ts.TextChangeRange[]): ts.TextChangeRange;
|
||||
28
node_modules/@volar/language-server/lib/utils/combineChangeRanges.js
generated
vendored
Normal file
28
node_modules/@volar/language-server/lib/utils/combineChangeRanges.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.combineChangeRanges = combineChangeRanges;
|
||||
function combineChangeRanges(...changeRanges) {
|
||||
let changeRange = changeRanges[0];
|
||||
for (let i = 1; i < changeRanges.length; i++) {
|
||||
const nextChangeRange = changeRanges[i];
|
||||
changeRange = combineTwoChanges(changeRange, nextChangeRange);
|
||||
}
|
||||
return changeRange;
|
||||
}
|
||||
// https://tsplay.dev/mMldVN - @browsnet
|
||||
function combineTwoChanges(a, b) {
|
||||
const aStart = a.span.start;
|
||||
const aEnd = a.span.start + a.span.length;
|
||||
const aDiff = a.newLength - a.span.length;
|
||||
const changeBegin = aStart + Math.min(a.span.length, a.newLength);
|
||||
const rollback = (start) => start > changeBegin ? Math.max(aStart, start - aDiff) : start;
|
||||
const bStart = rollback(b.span.start);
|
||||
const bEnd = rollback(b.span.start + b.span.length);
|
||||
const bDiff = b.newLength - b.span.length;
|
||||
const start = Math.min(aStart, bStart);
|
||||
const end = Math.max(aEnd, bEnd);
|
||||
const length = end - start;
|
||||
const newLength = aDiff + bDiff + length;
|
||||
return { span: { start, length }, newLength };
|
||||
}
|
||||
//# sourceMappingURL=combineChangeRanges.js.map
|
||||
24
node_modules/@volar/language-server/lib/utils/snapshotDocument.d.ts
generated
vendored
Normal file
24
node_modules/@volar/language-server/lib/utils/snapshotDocument.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import type * as ts from 'typescript';
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { Range, TextDocument } from 'vscode-languageserver-textdocument';
|
||||
export declare class SnapshotDocument implements TextDocument {
|
||||
private document;
|
||||
private snapshots;
|
||||
constructor(uri: string, languageId: string, version: number, text: string);
|
||||
get uri(): string;
|
||||
get languageId(): string;
|
||||
get version(): number;
|
||||
get lineCount(): number;
|
||||
getText(range?: Range): string;
|
||||
positionAt(offset: number): import("vscode-languageserver-textdocument").Position;
|
||||
offsetAt(position: vscode.Position): number;
|
||||
/**
|
||||
* Update the document with the given content changes and version.
|
||||
* If all changes is incremental, calculate the change range and add a new snapshot.
|
||||
* Otherwise, reset the changes.
|
||||
*/
|
||||
update(contentChanges: vscode.TextDocumentContentChangeEvent[], version: number): void;
|
||||
getSnapshot(): ts.IScriptSnapshot;
|
||||
private resetChanges;
|
||||
private clearUnreferencedVersions;
|
||||
}
|
||||
120
node_modules/@volar/language-server/lib/utils/snapshotDocument.js
generated
vendored
Normal file
120
node_modules/@volar/language-server/lib/utils/snapshotDocument.js
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SnapshotDocument = void 0;
|
||||
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
||||
const combineChangeRanges_1 = require("./combineChangeRanges");
|
||||
class SnapshotDocument {
|
||||
constructor(uri, languageId, version, text) {
|
||||
this.snapshots = [];
|
||||
this.document = vscode_languageserver_textdocument_1.TextDocument.create(uri, languageId, version, text);
|
||||
this.resetChanges();
|
||||
}
|
||||
get uri() {
|
||||
return this.document.uri;
|
||||
}
|
||||
get languageId() {
|
||||
return this.document.languageId;
|
||||
}
|
||||
get version() {
|
||||
return this.document.version;
|
||||
}
|
||||
get lineCount() {
|
||||
return this.document.lineCount;
|
||||
}
|
||||
getText(range) {
|
||||
return this.document.getText(range);
|
||||
}
|
||||
positionAt(offset) {
|
||||
return this.document.positionAt(offset);
|
||||
}
|
||||
offsetAt(position) {
|
||||
return this.document.offsetAt(position);
|
||||
}
|
||||
/**
|
||||
* Update the document with the given content changes and version.
|
||||
* If all changes is incremental, calculate the change range and add a new snapshot.
|
||||
* Otherwise, reset the changes.
|
||||
*/
|
||||
update(contentChanges, version) {
|
||||
if (contentChanges.every(change => 'range' in change)) {
|
||||
let changeRanges = [];
|
||||
for (const contentChange of contentChanges) {
|
||||
if (!('range' in contentChange)) {
|
||||
continue;
|
||||
}
|
||||
const start = this.offsetAt(contentChange.range.start);
|
||||
const length = contentChange.rangeLength ?? this.offsetAt(contentChange.range.end) - start;
|
||||
changeRanges.push({
|
||||
span: { start, length },
|
||||
newLength: contentChange.text.length
|
||||
});
|
||||
vscode_languageserver_textdocument_1.TextDocument.update(this.document, [contentChange], version);
|
||||
}
|
||||
this.snapshots.push({
|
||||
changeRange: (0, combineChangeRanges_1.combineChangeRanges)(...changeRanges),
|
||||
version,
|
||||
ref: undefined,
|
||||
});
|
||||
}
|
||||
else {
|
||||
vscode_languageserver_textdocument_1.TextDocument.update(this.document, contentChanges, version);
|
||||
this.resetChanges();
|
||||
}
|
||||
}
|
||||
getSnapshot() {
|
||||
this.clearUnreferencedVersions();
|
||||
const lastChange = this.snapshots[this.snapshots.length - 1];
|
||||
if (!lastChange.ref) {
|
||||
const text = this.document.getText();
|
||||
const changeRangeCache = new WeakMap();
|
||||
const snapshot = {
|
||||
getText: (start, end) => text.substring(start, end),
|
||||
getLength: () => text.length,
|
||||
getChangeRange: oldSnapshot => {
|
||||
if (!changeRangeCache.has(oldSnapshot)) {
|
||||
const oldIndex = this.snapshots.findIndex(change => change.ref?.deref() === oldSnapshot);
|
||||
if (oldIndex >= 0) {
|
||||
const start = oldIndex + 1;
|
||||
const end = this.snapshots.indexOf(lastChange) + 1;
|
||||
const changeRanges = this.snapshots
|
||||
.slice(start, end)
|
||||
.map(change => change.changeRange);
|
||||
const changeRange = (0, combineChangeRanges_1.combineChangeRanges)(...changeRanges);
|
||||
changeRangeCache.set(oldSnapshot, changeRange);
|
||||
}
|
||||
else {
|
||||
changeRangeCache.set(oldSnapshot, undefined);
|
||||
}
|
||||
}
|
||||
return changeRangeCache.get(oldSnapshot);
|
||||
},
|
||||
};
|
||||
lastChange.ref = new WeakRef(snapshot);
|
||||
}
|
||||
return lastChange.ref.deref();
|
||||
}
|
||||
resetChanges() {
|
||||
this.snapshots = [
|
||||
{
|
||||
changeRange: {
|
||||
span: {
|
||||
start: 0,
|
||||
length: 0,
|
||||
},
|
||||
newLength: this.document.getText().length,
|
||||
},
|
||||
version: this.document.version,
|
||||
ref: undefined,
|
||||
}
|
||||
];
|
||||
}
|
||||
clearUnreferencedVersions() {
|
||||
let firstReferencedIndex = 0;
|
||||
while (firstReferencedIndex < this.snapshots.length - 1 && !this.snapshots[firstReferencedIndex].ref?.deref()) {
|
||||
firstReferencedIndex++;
|
||||
}
|
||||
this.snapshots = this.snapshots.slice(firstReferencedIndex);
|
||||
}
|
||||
}
|
||||
exports.SnapshotDocument = SnapshotDocument;
|
||||
//# sourceMappingURL=snapshotDocument.js.map
|
||||
60
node_modules/@volar/language-server/node.d.ts
generated
vendored
Normal file
60
node_modules/@volar/language-server/node.d.ts
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
import * as vscode from 'vscode-languageserver/node';
|
||||
export * from 'vscode-languageserver/node';
|
||||
export * from './index';
|
||||
export * from './lib/project/simpleProject';
|
||||
export * from './lib/project/typescriptProject';
|
||||
export * from './lib/server';
|
||||
export declare function createConnection(): vscode._Connection<vscode._, vscode._, vscode._, vscode._, vscode._, vscode._, import("vscode-languageserver/lib/common/inlineCompletion.proposed").InlineCompletionFeatureShape, vscode._>;
|
||||
export declare function createServer(connection: vscode.Connection): {
|
||||
initializeParams: vscode.InitializeParams;
|
||||
project: import("./index").LanguageServerProject;
|
||||
languageServicePlugins: import("@volar/language-service/lib/types").LanguageServicePlugin<any>[];
|
||||
initialize(params: vscode.InitializeParams, project: import("./index").LanguageServerProject, languageServicePlugins: import("@volar/language-service/lib/types").LanguageServicePlugin[]): vscode.InitializeResult<import("./index").ExperimentalFeatures>;
|
||||
initialized(): void;
|
||||
shutdown(): void;
|
||||
configurations: {
|
||||
get: <T>(section: string, scopeUri?: string) => Promise<T | undefined>;
|
||||
onDidChange: (cb: vscode.NotificationHandler<vscode.DidChangeConfigurationParams>) => {
|
||||
dispose(): void;
|
||||
};
|
||||
};
|
||||
editorFeatures: void;
|
||||
documents: {
|
||||
all: () => import("./lib/utils/snapshotDocument").SnapshotDocument[];
|
||||
onDidChangeContent: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
|
||||
onDidOpen: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
|
||||
onDidClose: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
|
||||
onDidSave: vscode.Event<vscode.TextDocumentChangeEvent<import("./lib/utils/snapshotDocument").SnapshotDocument>>;
|
||||
get(uri: import("vscode-uri").URI): import("./lib/utils/snapshotDocument").SnapshotDocument | undefined;
|
||||
};
|
||||
workspaceFolders: {
|
||||
readonly all: import("vscode-uri").URI[];
|
||||
has(uri: import("vscode-uri").URI): boolean;
|
||||
onDidChange: (cb: vscode.NotificationHandler<vscode.WorkspaceFoldersChangeEvent>) => {
|
||||
dispose(): void;
|
||||
};
|
||||
};
|
||||
fileWatcher: {
|
||||
watchFiles: (patterns: string[]) => Promise<vscode.Disposable>;
|
||||
onDidChangeWatchedFiles: (cb: vscode.NotificationHandler<vscode.DidChangeWatchedFilesParams>) => {
|
||||
dispose: () => void;
|
||||
};
|
||||
};
|
||||
languageFeatures: {
|
||||
requestRefresh: (clearDiagnostics: boolean) => Promise<void>;
|
||||
};
|
||||
fileSystem: {
|
||||
readFile(uri: import("vscode-uri").URI): string | Thenable<string | undefined>;
|
||||
stat(uri: import("vscode-uri").URI): import("@volar/language-service/lib/types").FileStat | Thenable<import("@volar/language-service/lib/types").FileStat | undefined>;
|
||||
readDirectory(uri: import("vscode-uri").URI): import("@volar/language-service/lib/types").ProviderResult<[string, import("@volar/language-service/lib/types").FileType][]>;
|
||||
install(scheme: string, provider: import("@volar/language-service/lib/types").FileSystem): void;
|
||||
};
|
||||
env: import("./index").LanguageServerEnvironment;
|
||||
connection: vscode.Connection;
|
||||
onInitialize(callback: (serverCapabilities: vscode.ServerCapabilities<import("./index").ExperimentalFeatures>) => void): void;
|
||||
onInitialized(callback: () => void): void;
|
||||
};
|
||||
export declare function loadTsdkByPath(tsdk: string, locale: string | undefined): {
|
||||
typescript: typeof import("typescript");
|
||||
diagnosticMessages: import("typescript").MapLike<string> | undefined;
|
||||
};
|
||||
79
node_modules/@volar/language-server/node.js
generated
vendored
Normal file
79
node_modules/@volar/language-server/node.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createConnection = createConnection;
|
||||
exports.createServer = createServer;
|
||||
exports.loadTsdkByPath = loadTsdkByPath;
|
||||
const vscode = require("vscode-languageserver/node");
|
||||
const http_1 = require("./lib/fileSystemProviders/http");
|
||||
const node_1 = require("./lib/fileSystemProviders/node");
|
||||
const server_1 = require("./lib/server");
|
||||
__exportStar(require("vscode-languageserver/node"), exports);
|
||||
__exportStar(require("./index"), exports);
|
||||
__exportStar(require("./lib/project/simpleProject"), exports);
|
||||
__exportStar(require("./lib/project/typescriptProject"), exports);
|
||||
__exportStar(require("./lib/server"), exports);
|
||||
function createConnection() {
|
||||
return vscode.createConnection(vscode.ProposedFeatures.all);
|
||||
}
|
||||
function createServer(connection) {
|
||||
const server = (0, server_1.createServerBase)(connection, {
|
||||
timer: {
|
||||
setImmediate: setImmediate,
|
||||
},
|
||||
});
|
||||
server.fileSystem.install('file', node_1.provider);
|
||||
server.fileSystem.install('http', http_1.provider);
|
||||
server.fileSystem.install('https', http_1.provider);
|
||||
server.onInitialized(() => (0, http_1.listenEditorSettings)(server));
|
||||
return server;
|
||||
}
|
||||
function loadTsdkByPath(tsdk, locale) {
|
||||
locale = locale?.toLowerCase();
|
||||
// webpack compatibility
|
||||
const _require = eval('require');
|
||||
return {
|
||||
typescript: loadLib(),
|
||||
diagnosticMessages: loadLocalizedDiagnosticMessages(),
|
||||
};
|
||||
function loadLib() {
|
||||
for (const name of ['./typescript.js', './tsserverlibrary.js']) {
|
||||
try {
|
||||
return _require(_require.resolve(name, { paths: [tsdk] }));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
// for bun
|
||||
for (const name of ['typescript.js', 'tsserverlibrary.js']) {
|
||||
try {
|
||||
return _require(tsdk + '/' + name);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
throw new Error(`Can't find typescript.js or tsserverlibrary.js in ${JSON.stringify(tsdk)}`);
|
||||
}
|
||||
function loadLocalizedDiagnosticMessages() {
|
||||
if (locale === 'en') {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const path = _require.resolve(`./${locale}/diagnosticMessages.generated.json`, { paths: [tsdk] });
|
||||
return _require(path);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=node.js.map
|
||||
29
node_modules/@volar/language-server/package.json
generated
vendored
Normal file
29
node_modules/@volar/language-server/package.json
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "@volar/language-server",
|
||||
"version": "2.4.12",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"**/*.js",
|
||||
"**/*.d.ts"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/volarjs/volar.js.git",
|
||||
"directory": "packages/language-server"
|
||||
},
|
||||
"dependencies": {
|
||||
"@volar/language-core": "2.4.12",
|
||||
"@volar/language-service": "2.4.12",
|
||||
"@volar/typescript": "2.4.12",
|
||||
"path-browserify": "^1.0.1",
|
||||
"request-light": "^0.7.0",
|
||||
"vscode-languageserver": "^9.0.1",
|
||||
"vscode-languageserver-protocol": "^3.17.5",
|
||||
"vscode-languageserver-textdocument": "^1.0.11",
|
||||
"vscode-uri": "^3.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/path-browserify": "latest"
|
||||
},
|
||||
"gitHead": "17b9b8a1f522afd1aad1e598d2fd935680d8a8d7"
|
||||
}
|
||||
136
node_modules/@volar/language-server/protocol.d.ts
generated
vendored
Normal file
136
node_modules/@volar/language-server/protocol.d.ts
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
import type { CodeMapping } from '@volar/language-core';
|
||||
import type { DocumentDropEdit } from '@volar/language-service';
|
||||
import * as vscode from 'vscode-languageserver-protocol';
|
||||
export * from 'vscode-languageserver-protocol';
|
||||
/**
|
||||
* Client request server
|
||||
*/
|
||||
export declare namespace FindFileReferenceRequest {
|
||||
type ParamsType = {
|
||||
textDocument: vscode.TextDocumentIdentifier;
|
||||
};
|
||||
type ResponseType = vscode.Location[] | null | undefined;
|
||||
type ErrorType = never;
|
||||
const type: vscode.RequestType<ParamsType, ResponseType, never>;
|
||||
}
|
||||
export declare namespace GetMatchTsConfigRequest {
|
||||
type ParamsType = vscode.TextDocumentIdentifier;
|
||||
type ResponseType = {
|
||||
uri: string;
|
||||
} | null | undefined;
|
||||
type ErrorType = never;
|
||||
const type: vscode.RequestType<vscode.TextDocumentIdentifier, ResponseType, never>;
|
||||
}
|
||||
export declare namespace AutoInsertRequest {
|
||||
type ParamsType = {
|
||||
textDocument: vscode.TextDocumentIdentifier;
|
||||
selection: vscode.Position;
|
||||
change: {
|
||||
rangeOffset: number;
|
||||
rangeLength: number;
|
||||
text: string;
|
||||
};
|
||||
};
|
||||
type ResponseType = string | null | undefined;
|
||||
type ErrorType = never;
|
||||
const type: vscode.RequestType<ParamsType, ResponseType, never>;
|
||||
}
|
||||
export declare namespace WriteVirtualFilesNotification {
|
||||
const type: vscode.NotificationType<vscode.TextDocumentIdentifier>;
|
||||
}
|
||||
export declare namespace ReloadProjectNotification {
|
||||
const type: vscode.NotificationType<vscode.TextDocumentIdentifier>;
|
||||
}
|
||||
/**
|
||||
* Document Drop
|
||||
*/
|
||||
export declare namespace DocumentDropRequest {
|
||||
type ParamsType = vscode.TextDocumentPositionParams & {
|
||||
dataTransfer: {
|
||||
mimeType: string;
|
||||
value: any;
|
||||
file?: {
|
||||
name: string;
|
||||
uri?: string;
|
||||
};
|
||||
}[];
|
||||
};
|
||||
type ResponseType = DocumentDropEdit | null | undefined;
|
||||
type ErrorType = never;
|
||||
const type: vscode.RequestType<ParamsType, ResponseType, never>;
|
||||
}
|
||||
export declare namespace DocumentDrop_DataTransferItemAsStringRequest {
|
||||
type ParamsType = {
|
||||
mimeType: string;
|
||||
};
|
||||
type ResponseType = string;
|
||||
type ErrorType = never;
|
||||
const type: vscode.RequestType<ParamsType, string, never>;
|
||||
}
|
||||
export declare namespace DocumentDrop_DataTransferItemFileDataRequest {
|
||||
type ParamsType = {
|
||||
mimeType: string;
|
||||
};
|
||||
type ResponseType = Uint8Array;
|
||||
type ErrorType = never;
|
||||
const type: vscode.RequestType<ParamsType, ResponseType, never>;
|
||||
}
|
||||
/**
|
||||
* Labs
|
||||
*/
|
||||
export declare namespace UpdateVirtualCodeStateNotification {
|
||||
type ParamsType = {
|
||||
fileUri: string;
|
||||
virtualCodeId: string;
|
||||
disabled: boolean;
|
||||
};
|
||||
const type: vscode.NotificationType<ParamsType>;
|
||||
}
|
||||
export declare namespace UpdateServicePluginStateNotification {
|
||||
type ParamsType = {
|
||||
uri: string;
|
||||
serviceId: number;
|
||||
disabled: boolean;
|
||||
};
|
||||
const type: vscode.NotificationType<ParamsType>;
|
||||
}
|
||||
export declare namespace GetServicePluginsRequest {
|
||||
type ParamsType = vscode.TextDocumentIdentifier;
|
||||
type ResponseType = {
|
||||
id: number;
|
||||
name?: string;
|
||||
features: string[];
|
||||
disabled: boolean;
|
||||
}[] | null | undefined;
|
||||
type ErrorType = never;
|
||||
const type: vscode.RequestType<vscode.TextDocumentIdentifier, ResponseType, never>;
|
||||
}
|
||||
export declare namespace GetVirtualFileRequest {
|
||||
type VirtualCodeInfo = {
|
||||
fileUri: string;
|
||||
virtualCodeId: string;
|
||||
languageId: string;
|
||||
version: number;
|
||||
disabled: boolean;
|
||||
embeddedCodes: VirtualCodeInfo[];
|
||||
};
|
||||
type ParamsType = vscode.TextDocumentIdentifier;
|
||||
type ResponseType = VirtualCodeInfo | null | undefined;
|
||||
type ErrorType = never;
|
||||
const type: vscode.RequestType<vscode.TextDocumentIdentifier, ResponseType, never>;
|
||||
}
|
||||
export declare namespace GetVirtualCodeRequest {
|
||||
type ParamsType = {
|
||||
fileUri: string;
|
||||
virtualCodeId: string;
|
||||
};
|
||||
type ResponseType = {
|
||||
content: string;
|
||||
mappings: Record<string, CodeMapping[]>;
|
||||
};
|
||||
type ErrorType = never;
|
||||
const type: vscode.RequestType<ParamsType, ResponseType, never>;
|
||||
}
|
||||
export declare namespace LoadedTSFilesMetaRequest {
|
||||
const type: vscode.RequestType0<unknown, unknown>;
|
||||
}
|
||||
85
node_modules/@volar/language-server/protocol.js
generated
vendored
Normal file
85
node_modules/@volar/language-server/protocol.js
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LoadedTSFilesMetaRequest = exports.GetVirtualCodeRequest = exports.GetVirtualFileRequest = exports.GetServicePluginsRequest = exports.UpdateServicePluginStateNotification = exports.UpdateVirtualCodeStateNotification = exports.DocumentDrop_DataTransferItemFileDataRequest = exports.DocumentDrop_DataTransferItemAsStringRequest = exports.DocumentDropRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = void 0;
|
||||
const vscode = require("vscode-languageserver-protocol");
|
||||
__exportStar(require("vscode-languageserver-protocol"), exports);
|
||||
/**
|
||||
* Client request server
|
||||
*/
|
||||
var FindFileReferenceRequest;
|
||||
(function (FindFileReferenceRequest) {
|
||||
FindFileReferenceRequest.type = new vscode.RequestType('volar/client/findFileReference');
|
||||
})(FindFileReferenceRequest || (exports.FindFileReferenceRequest = FindFileReferenceRequest = {}));
|
||||
var GetMatchTsConfigRequest;
|
||||
(function (GetMatchTsConfigRequest) {
|
||||
GetMatchTsConfigRequest.type = new vscode.RequestType('volar/client/tsconfig');
|
||||
})(GetMatchTsConfigRequest || (exports.GetMatchTsConfigRequest = GetMatchTsConfigRequest = {}));
|
||||
var AutoInsertRequest;
|
||||
(function (AutoInsertRequest) {
|
||||
AutoInsertRequest.type = new vscode.RequestType('volar/client/autoInsert');
|
||||
})(AutoInsertRequest || (exports.AutoInsertRequest = AutoInsertRequest = {}));
|
||||
var WriteVirtualFilesNotification;
|
||||
(function (WriteVirtualFilesNotification) {
|
||||
WriteVirtualFilesNotification.type = new vscode.NotificationType('volar/client/writeVirtualFiles');
|
||||
})(WriteVirtualFilesNotification || (exports.WriteVirtualFilesNotification = WriteVirtualFilesNotification = {}));
|
||||
var ReloadProjectNotification;
|
||||
(function (ReloadProjectNotification) {
|
||||
ReloadProjectNotification.type = new vscode.NotificationType('volar/client/reloadProject');
|
||||
})(ReloadProjectNotification || (exports.ReloadProjectNotification = ReloadProjectNotification = {}));
|
||||
/**
|
||||
* Document Drop
|
||||
*/
|
||||
var DocumentDropRequest;
|
||||
(function (DocumentDropRequest) {
|
||||
DocumentDropRequest.type = new vscode.RequestType('volar/client/documentDrop');
|
||||
})(DocumentDropRequest || (exports.DocumentDropRequest = DocumentDropRequest = {}));
|
||||
var DocumentDrop_DataTransferItemAsStringRequest;
|
||||
(function (DocumentDrop_DataTransferItemAsStringRequest) {
|
||||
DocumentDrop_DataTransferItemAsStringRequest.type = new vscode.RequestType('volar/client/documentDrop/asString');
|
||||
})(DocumentDrop_DataTransferItemAsStringRequest || (exports.DocumentDrop_DataTransferItemAsStringRequest = DocumentDrop_DataTransferItemAsStringRequest = {}));
|
||||
var DocumentDrop_DataTransferItemFileDataRequest;
|
||||
(function (DocumentDrop_DataTransferItemFileDataRequest) {
|
||||
DocumentDrop_DataTransferItemFileDataRequest.type = new vscode.RequestType('volar/client/documentDrop/fileData');
|
||||
})(DocumentDrop_DataTransferItemFileDataRequest || (exports.DocumentDrop_DataTransferItemFileDataRequest = DocumentDrop_DataTransferItemFileDataRequest = {}));
|
||||
/**
|
||||
* Labs
|
||||
*/
|
||||
var UpdateVirtualCodeStateNotification;
|
||||
(function (UpdateVirtualCodeStateNotification) {
|
||||
UpdateVirtualCodeStateNotification.type = new vscode.NotificationType('volar/client/labs/updateVirtualFileState');
|
||||
})(UpdateVirtualCodeStateNotification || (exports.UpdateVirtualCodeStateNotification = UpdateVirtualCodeStateNotification = {}));
|
||||
var UpdateServicePluginStateNotification;
|
||||
(function (UpdateServicePluginStateNotification) {
|
||||
UpdateServicePluginStateNotification.type = new vscode.NotificationType('volar/client/labs/updateServicePluginState');
|
||||
})(UpdateServicePluginStateNotification || (exports.UpdateServicePluginStateNotification = UpdateServicePluginStateNotification = {}));
|
||||
var GetServicePluginsRequest;
|
||||
(function (GetServicePluginsRequest) {
|
||||
GetServicePluginsRequest.type = new vscode.RequestType('volar/client/servicePlugins');
|
||||
})(GetServicePluginsRequest || (exports.GetServicePluginsRequest = GetServicePluginsRequest = {}));
|
||||
var GetVirtualFileRequest;
|
||||
(function (GetVirtualFileRequest) {
|
||||
GetVirtualFileRequest.type = new vscode.RequestType('volar/client/virtualFiles');
|
||||
})(GetVirtualFileRequest || (exports.GetVirtualFileRequest = GetVirtualFileRequest = {}));
|
||||
var GetVirtualCodeRequest;
|
||||
(function (GetVirtualCodeRequest) {
|
||||
GetVirtualCodeRequest.type = new vscode.RequestType('volar/client/virtualFile');
|
||||
})(GetVirtualCodeRequest || (exports.GetVirtualCodeRequest = GetVirtualCodeRequest = {}));
|
||||
var LoadedTSFilesMetaRequest;
|
||||
(function (LoadedTSFilesMetaRequest) {
|
||||
LoadedTSFilesMetaRequest.type = new vscode.RequestType0('volar/client/loadedTsFiles');
|
||||
})(LoadedTSFilesMetaRequest || (exports.LoadedTSFilesMetaRequest = LoadedTSFilesMetaRequest = {}));
|
||||
//# sourceMappingURL=protocol.js.map
|
||||
21
node_modules/@volar/language-service/LICENSE
generated
vendored
Normal file
21
node_modules/@volar/language-service/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-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.
|
||||
6
node_modules/@volar/language-service/index.d.ts
generated
vendored
Normal file
6
node_modules/@volar/language-service/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export * from '@volar/language-core';
|
||||
export * from './lib/languageService';
|
||||
export { mergeWorkspaceEdits } from './lib/features/provideRenameEdits';
|
||||
export * from './lib/types';
|
||||
export * from './lib/utils/transform';
|
||||
export * from './lib/utils/uriMap';
|
||||
25
node_modules/@volar/language-service/index.js
generated
vendored
Normal file
25
node_modules/@volar/language-service/index.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.mergeWorkspaceEdits = void 0;
|
||||
__exportStar(require("@volar/language-core"), exports);
|
||||
__exportStar(require("./lib/languageService"), exports);
|
||||
var provideRenameEdits_1 = require("./lib/features/provideRenameEdits");
|
||||
Object.defineProperty(exports, "mergeWorkspaceEdits", { enumerable: true, get: function () { return provideRenameEdits_1.mergeWorkspaceEdits; } });
|
||||
__exportStar(require("./lib/types"), exports);
|
||||
__exportStar(require("./lib/utils/transform"), exports);
|
||||
__exportStar(require("./lib/utils/uriMap"), exports);
|
||||
//# sourceMappingURL=index.js.map
|
||||
8
node_modules/@volar/language-service/lib/features/provideAutoInsertSnippet.d.ts
generated
vendored
Normal file
8
node_modules/@volar/language-service/lib/features/provideAutoInsertSnippet.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
export declare function register(context: LanguageServiceContext): (uri: URI, selection: vscode.Position, change: {
|
||||
rangeOffset: number;
|
||||
rangeLength: number;
|
||||
text: string;
|
||||
}, token?: vscode.CancellationToken) => Promise<string | undefined>;
|
||||
31
node_modules/@volar/language-service/lib/features/provideAutoInsertSnippet.js
generated
vendored
Normal file
31
node_modules/@volar/language-service/lib/features/provideAutoInsertSnippet.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
function register(context) {
|
||||
return (uri, selection, change, token = cancellation_1.NoneCancellationToken) => {
|
||||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => ({ selection, change }), function* (docs) {
|
||||
for (const mappedPosition of (0, featureWorkers_1.getGeneratedPositions)(docs, selection, language_core_1.isAutoInsertEnabled)) {
|
||||
for (const mapped of docs[2].toGeneratedLocation(change.rangeOffset)) {
|
||||
yield {
|
||||
selection: mappedPosition,
|
||||
change: {
|
||||
text: change.text,
|
||||
rangeOffset: mapped[0],
|
||||
rangeLength: change.rangeLength,
|
||||
},
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, (plugin, document, args) => {
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
return plugin[1].provideAutoInsertSnippet?.(document, args.selection, args.change, token);
|
||||
}, snippet => snippet);
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=provideAutoInsertSnippet.js.map
|
||||
17
node_modules/@volar/language-service/lib/features/provideCallHierarchyItems.d.ts
generated
vendored
Normal file
17
node_modules/@volar/language-service/lib/features/provideCallHierarchyItems.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
export interface PluginCallHierarchyData {
|
||||
uri: string;
|
||||
original: Pick<vscode.CallHierarchyItem, 'data'>;
|
||||
pluginIndex: number;
|
||||
embeddedDocumentUri: string | undefined;
|
||||
}
|
||||
export declare function register(context: LanguageServiceContext): {
|
||||
getCallHierarchyItems(uri: URI, position: vscode.Position, token?: vscode.CancellationToken): Promise<vscode.CallHierarchyItem[] | undefined>;
|
||||
getTypeHierarchyItems(uri: URI, position: vscode.Position, token?: vscode.CancellationToken): Promise<vscode.TypeHierarchyItem[] | undefined>;
|
||||
getCallHierarchyIncomingCalls(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Promise<vscode.CallHierarchyIncomingCall[]>;
|
||||
getCallHierarchyOutgoingCalls(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Promise<vscode.CallHierarchyOutgoingCall[]>;
|
||||
getTypeHierarchySupertypes(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Promise<vscode.TypeHierarchyItem[] | undefined>;
|
||||
getTypeHierarchySubtypes(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Promise<vscode.TypeHierarchyItem[] | undefined>;
|
||||
};
|
||||
240
node_modules/@volar/language-service/lib/features/provideCallHierarchyItems.js
generated
vendored
Normal file
240
node_modules/@volar/language-service/lib/features/provideCallHierarchyItems.js
generated
vendored
Normal file
@@ -0,0 +1,240 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const dedupe = require("../utils/dedupe");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
function register(context) {
|
||||
return {
|
||||
getCallHierarchyItems(uri, position, token = cancellation_1.NoneCancellationToken) {
|
||||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, docs => (0, featureWorkers_1.getGeneratedPositions)(docs, position, language_core_1.isCallHierarchyEnabled), async (plugin, document, position, map) => {
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
const items = await plugin[1].provideCallHierarchyItems?.(document, position, token);
|
||||
items?.forEach(item => {
|
||||
item.data = {
|
||||
uri: uri.toString(),
|
||||
original: {
|
||||
data: item.data,
|
||||
},
|
||||
pluginIndex: context.plugins.indexOf(plugin),
|
||||
embeddedDocumentUri: map?.[1].uri,
|
||||
};
|
||||
});
|
||||
return items;
|
||||
}, (data, map) => {
|
||||
if (!map) {
|
||||
return data;
|
||||
}
|
||||
return data
|
||||
.map(item => transformHierarchyItem(item, [])?.[0])
|
||||
.filter(item => !!item);
|
||||
}, arr => dedupe.withLocations(arr.flat()));
|
||||
},
|
||||
getTypeHierarchyItems(uri, position, token = cancellation_1.NoneCancellationToken) {
|
||||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, docs => (0, featureWorkers_1.getGeneratedPositions)(docs, position, language_core_1.isTypeHierarchyEnabled), async (plugin, document, position, map) => {
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
const items = await plugin[1].provideTypeHierarchyItems?.(document, position, token);
|
||||
items?.forEach(item => {
|
||||
item.data = {
|
||||
uri: uri.toString(),
|
||||
original: {
|
||||
data: item.data,
|
||||
},
|
||||
pluginIndex: context.plugins.indexOf(plugin),
|
||||
embeddedDocumentUri: map?.[1].uri,
|
||||
};
|
||||
});
|
||||
return items;
|
||||
}, (data, map) => {
|
||||
if (!map) {
|
||||
return data;
|
||||
}
|
||||
return data
|
||||
.map(item => transformHierarchyItem(item, [])?.[0])
|
||||
.filter(item => !!item);
|
||||
}, arr => dedupe.withLocations(arr.flat()));
|
||||
},
|
||||
async getCallHierarchyIncomingCalls(item, token) {
|
||||
const data = item.data;
|
||||
let incomingItems = [];
|
||||
if (data) {
|
||||
const plugin = context.plugins[data.pluginIndex];
|
||||
if (!plugin[1].provideCallHierarchyIncomingCalls) {
|
||||
return incomingItems;
|
||||
}
|
||||
Object.assign(item, data.original);
|
||||
if (data.embeddedDocumentUri) {
|
||||
const isEmbeddedContent = !!context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(data.embeddedDocumentUri));
|
||||
if (isEmbeddedContent) {
|
||||
const _calls = await plugin[1].provideCallHierarchyIncomingCalls(item, token);
|
||||
for (const _call of _calls) {
|
||||
const calls = transformHierarchyItem(_call.from, _call.fromRanges);
|
||||
if (!calls) {
|
||||
continue;
|
||||
}
|
||||
incomingItems.push({
|
||||
from: calls[0],
|
||||
fromRanges: calls[1],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const _calls = await plugin[1].provideCallHierarchyIncomingCalls(item, token);
|
||||
for (const _call of _calls) {
|
||||
const calls = transformHierarchyItem(_call.from, _call.fromRanges);
|
||||
if (!calls) {
|
||||
continue;
|
||||
}
|
||||
incomingItems.push({
|
||||
from: calls[0],
|
||||
fromRanges: calls[1],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return dedupe.withCallHierarchyIncomingCalls(incomingItems);
|
||||
},
|
||||
async getCallHierarchyOutgoingCalls(item, token) {
|
||||
const data = item.data;
|
||||
let items = [];
|
||||
if (data) {
|
||||
const plugin = context.plugins[data.pluginIndex];
|
||||
if (!plugin[1].provideCallHierarchyOutgoingCalls) {
|
||||
return items;
|
||||
}
|
||||
Object.assign(item, data.original);
|
||||
if (data.embeddedDocumentUri) {
|
||||
const isEmbeddedContent = !!context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(data.embeddedDocumentUri));
|
||||
if (isEmbeddedContent) {
|
||||
const _calls = await plugin[1].provideCallHierarchyOutgoingCalls(item, token);
|
||||
for (const call of _calls) {
|
||||
const calls = transformHierarchyItem(call.to, call.fromRanges);
|
||||
if (!calls) {
|
||||
continue;
|
||||
}
|
||||
items.push({
|
||||
to: calls[0],
|
||||
fromRanges: calls[1],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const _calls = await plugin[1].provideCallHierarchyOutgoingCalls(item, token);
|
||||
for (const call of _calls) {
|
||||
const calls = transformHierarchyItem(call.to, call.fromRanges);
|
||||
if (!calls) {
|
||||
continue;
|
||||
}
|
||||
items.push({
|
||||
to: calls[0],
|
||||
fromRanges: calls[1],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return dedupe.withCallHierarchyOutgoingCalls(items);
|
||||
},
|
||||
async getTypeHierarchySupertypes(item, token) {
|
||||
const data = item.data;
|
||||
if (data) {
|
||||
const plugin = context.plugins[data.pluginIndex];
|
||||
if (!plugin[1].provideTypeHierarchySupertypes) {
|
||||
return [];
|
||||
}
|
||||
Object.assign(item, data.original);
|
||||
if (data.embeddedDocumentUri) {
|
||||
const isEmbeddedContent = !!context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(data.embeddedDocumentUri));
|
||||
if (isEmbeddedContent) {
|
||||
const items = await plugin[1].provideTypeHierarchySupertypes(item, token);
|
||||
return items
|
||||
.map(item => transformHierarchyItem(item, [])?.[0])
|
||||
.filter(item => !!item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const items = await plugin[1].provideTypeHierarchySupertypes(item, token);
|
||||
return items
|
||||
.map(item => transformHierarchyItem(item, [])?.[0])
|
||||
.filter(item => !!item);
|
||||
}
|
||||
}
|
||||
},
|
||||
async getTypeHierarchySubtypes(item, token) {
|
||||
const data = item.data;
|
||||
if (data) {
|
||||
const plugin = context.plugins[data.pluginIndex];
|
||||
if (!plugin[1].provideTypeHierarchySubtypes) {
|
||||
return [];
|
||||
}
|
||||
Object.assign(item, data.original);
|
||||
if (data.embeddedDocumentUri) {
|
||||
const isEmbeddedContent = !!context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(data.embeddedDocumentUri));
|
||||
if (isEmbeddedContent) {
|
||||
const items = await plugin[1].provideTypeHierarchySubtypes(item, token);
|
||||
return items
|
||||
.map(item => transformHierarchyItem(item, [])?.[0])
|
||||
.filter(item => !!item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const items = await plugin[1].provideTypeHierarchySubtypes(item, token);
|
||||
return items
|
||||
.map(item => transformHierarchyItem(item, [])?.[0])
|
||||
.filter(item => !!item);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
function transformHierarchyItem(tsItem, tsRanges) {
|
||||
const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(tsItem.uri));
|
||||
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
||||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
||||
if (!sourceScript || !virtualCode) {
|
||||
return [tsItem, tsRanges];
|
||||
}
|
||||
const embeddedDocument = context.documents.get(context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id), virtualCode.languageId, virtualCode.snapshot);
|
||||
for (const [sourceScript, map] of context.language.maps.forEach(virtualCode)) {
|
||||
const sourceDocument = context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot);
|
||||
const docs = [sourceDocument, embeddedDocument, map];
|
||||
let range = (0, featureWorkers_1.getSourceRange)(docs, tsItem.range);
|
||||
if (!range) {
|
||||
// TODO: <script> range
|
||||
range = {
|
||||
start: sourceDocument.positionAt(0),
|
||||
end: sourceDocument.positionAt(sourceDocument.getText().length),
|
||||
};
|
||||
}
|
||||
const selectionRange = (0, featureWorkers_1.getSourceRange)(docs, tsItem.selectionRange);
|
||||
if (!selectionRange) {
|
||||
continue;
|
||||
}
|
||||
const vueRanges = tsRanges.map(tsRange => (0, featureWorkers_1.getSourceRange)(docs, tsRange)).filter(range => !!range);
|
||||
const vueItem = {
|
||||
...tsItem,
|
||||
name: tsItem.name === embeddedDocument.uri.substring(embeddedDocument.uri.lastIndexOf('/') + 1)
|
||||
? sourceDocument.uri.substring(sourceDocument.uri.lastIndexOf('/') + 1)
|
||||
: tsItem.name,
|
||||
uri: sourceDocument.uri,
|
||||
// TS Bug: `range: range` not works
|
||||
range: {
|
||||
start: range.start,
|
||||
end: range.end,
|
||||
},
|
||||
selectionRange: {
|
||||
start: selectionRange.start,
|
||||
end: selectionRange.end,
|
||||
},
|
||||
};
|
||||
return [vueItem, vueRanges];
|
||||
}
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=provideCallHierarchyItems.js.map
|
||||
10
node_modules/@volar/language-service/lib/features/provideCodeActions.d.ts
generated
vendored
Normal file
10
node_modules/@volar/language-service/lib/features/provideCodeActions.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
export interface ServiceCodeActionData {
|
||||
uri: string;
|
||||
version: number;
|
||||
original: Pick<vscode.CodeAction, 'data' | 'edit'>;
|
||||
pluginIndex: number;
|
||||
}
|
||||
export declare function register(context: LanguageServiceContext): (uri: URI, range: vscode.Range, codeActionContext: vscode.CodeActionContext, token?: vscode.CancellationToken) => Promise<vscode.CodeAction[] | undefined>;
|
||||
97
node_modules/@volar/language-service/lib/features/provideCodeActions.js
generated
vendored
Normal file
97
node_modules/@volar/language-service/lib/features/provideCodeActions.js
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const common_1 = require("../utils/common");
|
||||
const dedupe = require("../utils/dedupe");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
const transform_1 = require("../utils/transform");
|
||||
function register(context) {
|
||||
return async (uri, range, codeActionContext, token = cancellation_1.NoneCancellationToken) => {
|
||||
const sourceScript = context.language.scripts.get(uri);
|
||||
if (!sourceScript) {
|
||||
return;
|
||||
}
|
||||
const transformedCodeActions = new WeakSet();
|
||||
return await (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => ({ range, codeActionContext }), function* (docs) {
|
||||
const _codeActionContext = {
|
||||
diagnostics: (0, transform_1.transformLocations)(codeActionContext.diagnostics, range => (0, featureWorkers_1.getGeneratedRange)(docs, range)),
|
||||
only: codeActionContext.only,
|
||||
};
|
||||
const mapped = (0, common_1.findOverlapCodeRange)(docs[0].offsetAt(range.start), docs[0].offsetAt(range.end), docs[2], language_core_1.isCodeActionsEnabled);
|
||||
if (mapped) {
|
||||
yield {
|
||||
range: {
|
||||
start: docs[1].positionAt(mapped.start),
|
||||
end: docs[1].positionAt(mapped.end),
|
||||
},
|
||||
codeActionContext: _codeActionContext,
|
||||
};
|
||||
}
|
||||
}, async (plugin, document, { range, codeActionContext }) => {
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
const pluginIndex = context.plugins.indexOf(plugin);
|
||||
const diagnostics = codeActionContext.diagnostics.filter(diagnostic => {
|
||||
const data = diagnostic.data;
|
||||
if (data && data.version !== document.version) {
|
||||
return false;
|
||||
}
|
||||
return data?.pluginIndex === pluginIndex;
|
||||
}).map(diagnostic => {
|
||||
const data = diagnostic.data;
|
||||
return {
|
||||
...diagnostic,
|
||||
...data.original,
|
||||
};
|
||||
});
|
||||
const codeActions = await plugin[1].provideCodeActions?.(document, range, {
|
||||
...codeActionContext,
|
||||
diagnostics,
|
||||
}, token);
|
||||
codeActions?.forEach(codeAction => {
|
||||
if (plugin[1].resolveCodeAction) {
|
||||
codeAction.data = {
|
||||
uri: uri.toString(),
|
||||
version: document.version,
|
||||
original: {
|
||||
data: codeAction.data,
|
||||
edit: codeAction.edit,
|
||||
},
|
||||
pluginIndex: context.plugins.indexOf(plugin),
|
||||
};
|
||||
}
|
||||
else {
|
||||
delete codeAction.data;
|
||||
}
|
||||
});
|
||||
if (codeActions && plugin[1].transformCodeAction) {
|
||||
for (let i = 0; i < codeActions.length; i++) {
|
||||
const transformed = plugin[1].transformCodeAction(codeActions[i]);
|
||||
if (transformed) {
|
||||
codeActions[i] = transformed;
|
||||
transformedCodeActions.add(transformed);
|
||||
}
|
||||
}
|
||||
}
|
||||
return codeActions;
|
||||
}, actions => actions
|
||||
.map(action => {
|
||||
if (transformedCodeActions.has(action)) {
|
||||
return action;
|
||||
}
|
||||
if (action.edit) {
|
||||
const edit = (0, transform_1.transformWorkspaceEdit)(action.edit, context, 'codeAction');
|
||||
if (!edit) {
|
||||
return;
|
||||
}
|
||||
action.edit = edit;
|
||||
}
|
||||
return action;
|
||||
})
|
||||
.filter(action => !!action), arr => dedupe.withCodeAction(arr.flat()));
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=provideCodeActions.js.map
|
||||
17
node_modules/@volar/language-service/lib/features/provideCodeLenses.d.ts
generated
vendored
Normal file
17
node_modules/@volar/language-service/lib/features/provideCodeLenses.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
export interface ServiceCodeLensData {
|
||||
kind: 'normal';
|
||||
uri: string;
|
||||
original: Pick<vscode.CodeLens, 'data'>;
|
||||
pluginIndex: number;
|
||||
}
|
||||
export interface ServiceReferencesCodeLensData {
|
||||
kind: 'references';
|
||||
sourceFileUri: string;
|
||||
workerFileUri: string;
|
||||
workerFileRange: vscode.Range;
|
||||
pluginIndex: number;
|
||||
}
|
||||
export declare function register(context: LanguageServiceContext): (uri: URI, token?: vscode.CancellationToken) => Promise<vscode.CodeLens[]>;
|
||||
64
node_modules/@volar/language-service/lib/features/provideCodeLenses.js
generated
vendored
Normal file
64
node_modules/@volar/language-service/lib/features/provideCodeLenses.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
function register(context) {
|
||||
return async (uri, token = cancellation_1.NoneCancellationToken) => {
|
||||
return await (0, featureWorkers_1.documentFeatureWorker)(context, uri, docs => docs[2].mappings.some(mapping => (0, language_core_1.isCodeLensEnabled)(mapping.data)), async (plugin, document) => {
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
let codeLens = await plugin[1].provideCodeLenses?.(document, token);
|
||||
const pluginIndex = context.plugins.indexOf(plugin);
|
||||
codeLens?.forEach(codeLens => {
|
||||
if (plugin[1].resolveCodeLens) {
|
||||
codeLens.data = {
|
||||
kind: 'normal',
|
||||
uri: uri.toString(),
|
||||
original: {
|
||||
data: codeLens.data,
|
||||
},
|
||||
pluginIndex,
|
||||
};
|
||||
}
|
||||
else {
|
||||
delete codeLens.data;
|
||||
}
|
||||
});
|
||||
const ranges = await plugin[1].provideReferencesCodeLensRanges?.(document, token);
|
||||
const referencesCodeLens = ranges?.map(range => ({
|
||||
range,
|
||||
data: {
|
||||
kind: 'references',
|
||||
sourceFileUri: uri.toString(),
|
||||
workerFileUri: document.uri,
|
||||
workerFileRange: range,
|
||||
pluginIndex: pluginIndex,
|
||||
},
|
||||
}));
|
||||
codeLens = [
|
||||
...codeLens ?? [],
|
||||
...referencesCodeLens ?? [],
|
||||
];
|
||||
return codeLens;
|
||||
}, (data, docs) => {
|
||||
if (!docs) {
|
||||
return data;
|
||||
}
|
||||
return data
|
||||
.map(codeLens => {
|
||||
const range = (0, featureWorkers_1.getSourceRange)(docs, codeLens.range, language_core_1.isCodeLensEnabled);
|
||||
if (range) {
|
||||
return {
|
||||
...codeLens,
|
||||
range,
|
||||
};
|
||||
}
|
||||
})
|
||||
.filter(codeLens => !!codeLens);
|
||||
}, arr => arr.flat()) ?? [];
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=provideCodeLenses.js.map
|
||||
4
node_modules/@volar/language-service/lib/features/provideColorPresentations.d.ts
generated
vendored
Normal file
4
node_modules/@volar/language-service/lib/features/provideColorPresentations.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
export declare function register(context: LanguageServiceContext): (uri: URI, color: vscode.Color, range: vscode.Range, token?: vscode.CancellationToken) => Promise<vscode.ColorPresentation[] | undefined>;
|
||||
46
node_modules/@volar/language-service/lib/features/provideColorPresentations.js
generated
vendored
Normal file
46
node_modules/@volar/language-service/lib/features/provideColorPresentations.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
function register(context) {
|
||||
return (uri, color, range, token = cancellation_1.NoneCancellationToken) => {
|
||||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => range, function* (docs) {
|
||||
for (const mappedRange of (0, featureWorkers_1.getGeneratedRanges)(docs, range, language_core_1.isColorEnabled)) {
|
||||
yield mappedRange;
|
||||
}
|
||||
}, (plugin, document, range) => {
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
return plugin[1].provideColorPresentations?.(document, color, range, token);
|
||||
}, (data, docs) => {
|
||||
if (!docs) {
|
||||
return data;
|
||||
}
|
||||
return data
|
||||
.map(colorPresentation => {
|
||||
if (colorPresentation.textEdit) {
|
||||
const range = (0, featureWorkers_1.getSourceRange)(docs, colorPresentation.textEdit.range);
|
||||
if (!range) {
|
||||
return undefined;
|
||||
}
|
||||
colorPresentation.textEdit.range = range;
|
||||
}
|
||||
if (colorPresentation.additionalTextEdits) {
|
||||
for (const textEdit of colorPresentation.additionalTextEdits) {
|
||||
const range = (0, featureWorkers_1.getSourceRange)(docs, textEdit.range);
|
||||
if (!range) {
|
||||
return undefined;
|
||||
}
|
||||
textEdit.range = range;
|
||||
}
|
||||
}
|
||||
return colorPresentation;
|
||||
})
|
||||
.filter(colorPresentation => !!colorPresentation);
|
||||
});
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=provideColorPresentations.js.map
|
||||
10
node_modules/@volar/language-service/lib/features/provideCompletionItems.d.ts
generated
vendored
Normal file
10
node_modules/@volar/language-service/lib/features/provideCompletionItems.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
export interface ServiceCompletionData {
|
||||
uri: string;
|
||||
original: Pick<vscode.CompletionItem, 'additionalTextEdits' | 'textEdit' | 'data'>;
|
||||
pluginIndex: number;
|
||||
embeddedDocumentUri: string | undefined;
|
||||
}
|
||||
export declare function register(context: LanguageServiceContext): (uri: URI, position: vscode.Position, completionContext?: vscode.CompletionContext, token?: vscode.CancellationToken) => Promise<vscode.CompletionList>;
|
||||
205
node_modules/@volar/language-service/lib/features/provideCompletionItems.js
generated
vendored
Normal file
205
node_modules/@volar/language-service/lib/features/provideCompletionItems.js
generated
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
const transform_1 = require("../utils/transform");
|
||||
function register(context) {
|
||||
let lastResult;
|
||||
return async (uri, position, completionContext = { triggerKind: 1, }, token = cancellation_1.NoneCancellationToken) => {
|
||||
let langaugeIdAndSnapshot;
|
||||
let sourceScript;
|
||||
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
||||
if (decoded) {
|
||||
langaugeIdAndSnapshot = context.language.scripts.get(decoded[0])?.generated?.embeddedCodes.get(decoded[1]);
|
||||
}
|
||||
else {
|
||||
sourceScript = context.language.scripts.get(uri);
|
||||
langaugeIdAndSnapshot = sourceScript;
|
||||
}
|
||||
if (!langaugeIdAndSnapshot) {
|
||||
return {
|
||||
isIncomplete: false,
|
||||
items: [],
|
||||
};
|
||||
}
|
||||
if (completionContext?.triggerKind === 3
|
||||
&& lastResult?.uri.toString() === uri.toString()) {
|
||||
for (const cacheData of lastResult.results) {
|
||||
if (!cacheData.list?.isIncomplete) {
|
||||
continue;
|
||||
}
|
||||
const pluginIndex = context.plugins.findIndex(plugin => plugin[1] === cacheData.plugin);
|
||||
if (cacheData.embeddedDocumentUri) {
|
||||
const decoded = context.decodeEmbeddedDocumentUri(cacheData.embeddedDocumentUri);
|
||||
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
||||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
||||
if (!sourceScript || !virtualCode) {
|
||||
continue;
|
||||
}
|
||||
const embeddedDocument = context.documents.get(context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id), virtualCode.languageId, virtualCode.snapshot);
|
||||
for (const [sourceScript, map] of context.language.maps.forEach(virtualCode)) {
|
||||
const sourceDocument = context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot);
|
||||
const docs = [sourceDocument, embeddedDocument, map];
|
||||
for (const mapped of (0, featureWorkers_1.getGeneratedPositions)(docs, position, data => (0, language_core_1.isCompletionEnabled)(data))) {
|
||||
if (!cacheData.plugin.provideCompletionItems) {
|
||||
continue;
|
||||
}
|
||||
cacheData.list = await cacheData.plugin.provideCompletionItems(embeddedDocument, mapped, completionContext, token);
|
||||
if (!cacheData.list) {
|
||||
continue;
|
||||
}
|
||||
for (const item of cacheData.list.items) {
|
||||
if (cacheData.plugin.resolveCompletionItem) {
|
||||
item.data = {
|
||||
uri: uri.toString(),
|
||||
original: {
|
||||
additionalTextEdits: item.additionalTextEdits,
|
||||
textEdit: item.textEdit,
|
||||
data: item.data,
|
||||
},
|
||||
pluginIndex: pluginIndex,
|
||||
embeddedDocumentUri: embeddedDocument.uri,
|
||||
};
|
||||
}
|
||||
else {
|
||||
delete item.data;
|
||||
}
|
||||
}
|
||||
cacheData.list = (0, transform_1.transformCompletionList)(cacheData.list, range => (0, featureWorkers_1.getSourceRange)(docs, range), embeddedDocument, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!cacheData.plugin.provideCompletionItems) {
|
||||
continue;
|
||||
}
|
||||
const document = context.documents.get(uri, langaugeIdAndSnapshot.languageId, langaugeIdAndSnapshot.snapshot);
|
||||
cacheData.list = await cacheData.plugin.provideCompletionItems(document, position, completionContext, token);
|
||||
if (!cacheData.list) {
|
||||
continue;
|
||||
}
|
||||
for (const item of cacheData.list.items) {
|
||||
if (cacheData.plugin.resolveCompletionItem) {
|
||||
item.data = {
|
||||
uri: uri.toString(),
|
||||
original: {
|
||||
additionalTextEdits: item.additionalTextEdits,
|
||||
textEdit: item.textEdit,
|
||||
data: item.data,
|
||||
},
|
||||
pluginIndex: pluginIndex,
|
||||
embeddedDocumentUri: undefined,
|
||||
};
|
||||
}
|
||||
else {
|
||||
delete item.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastResult = {
|
||||
uri,
|
||||
results: [],
|
||||
};
|
||||
// monky fix https://github.com/johnsoncodehk/volar/issues/1358
|
||||
let isFirstMapping = true;
|
||||
let mainCompletionUri;
|
||||
const sortedPlugins = [...context.plugins]
|
||||
.filter(plugin => !context.disabledServicePlugins.has(plugin[1]))
|
||||
.sort((a, b) => sortServices(a[1], b[1]));
|
||||
const worker = async (document, position, docs, codeInfo) => {
|
||||
for (const plugin of sortedPlugins) {
|
||||
if (token.isCancellationRequested) {
|
||||
break;
|
||||
}
|
||||
if (!plugin[1].provideCompletionItems) {
|
||||
continue;
|
||||
}
|
||||
if (plugin[1].isAdditionalCompletion && !isFirstMapping) {
|
||||
continue;
|
||||
}
|
||||
if (completionContext?.triggerCharacter && !plugin[0].capabilities.completionProvider?.triggerCharacters?.includes(completionContext.triggerCharacter)) {
|
||||
continue;
|
||||
}
|
||||
const isAdditional = (codeInfo && typeof codeInfo.completion === 'object' && codeInfo.completion.isAdditional) || plugin[1].isAdditionalCompletion;
|
||||
if (mainCompletionUri && (!isAdditional || mainCompletionUri !== document.uri)) {
|
||||
continue;
|
||||
}
|
||||
// avoid duplicate items with .vue and .vue.html
|
||||
if (plugin[1].isAdditionalCompletion && lastResult?.results.some(data => data.plugin === plugin[1])) {
|
||||
continue;
|
||||
}
|
||||
let completionList = await plugin[1].provideCompletionItems(document, position, completionContext, token);
|
||||
if (!completionList || !completionList.items.length) {
|
||||
continue;
|
||||
}
|
||||
if (typeof codeInfo?.completion === 'object' && codeInfo.completion.onlyImport) {
|
||||
completionList.items = completionList.items.filter(item => !!item.labelDetails);
|
||||
}
|
||||
if (!isAdditional) {
|
||||
mainCompletionUri = document.uri;
|
||||
}
|
||||
const pluginIndex = context.plugins.indexOf(plugin);
|
||||
for (const item of completionList.items) {
|
||||
if (plugin[1].resolveCompletionItem) {
|
||||
item.data = {
|
||||
uri: uri.toString(),
|
||||
original: {
|
||||
additionalTextEdits: item.additionalTextEdits,
|
||||
textEdit: item.textEdit,
|
||||
data: item.data,
|
||||
},
|
||||
pluginIndex,
|
||||
embeddedDocumentUri: docs ? document.uri : undefined,
|
||||
};
|
||||
}
|
||||
else {
|
||||
delete item.data;
|
||||
}
|
||||
}
|
||||
if (docs) {
|
||||
completionList = (0, transform_1.transformCompletionList)(completionList, range => (0, featureWorkers_1.getSourceRange)(docs, range, language_core_1.isCompletionEnabled), document, context);
|
||||
}
|
||||
lastResult?.results.push({
|
||||
embeddedDocumentUri: docs ? vscode_uri_1.URI.parse(document.uri) : undefined,
|
||||
plugin: plugin[1],
|
||||
list: completionList,
|
||||
});
|
||||
}
|
||||
isFirstMapping = false;
|
||||
};
|
||||
if (sourceScript?.generated) {
|
||||
for (const docs of (0, featureWorkers_1.forEachEmbeddedDocument)(context, sourceScript, sourceScript.generated.root)) {
|
||||
let _data;
|
||||
for (const mappedPosition of (0, featureWorkers_1.getGeneratedPositions)(docs, position, data => {
|
||||
_data = data;
|
||||
return (0, language_core_1.isCompletionEnabled)(data);
|
||||
})) {
|
||||
await worker(docs[1], mappedPosition, docs, _data);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const document = context.documents.get(uri, langaugeIdAndSnapshot.languageId, langaugeIdAndSnapshot.snapshot);
|
||||
await worker(document, position);
|
||||
}
|
||||
}
|
||||
return combineCompletionList(lastResult.results.map(cacheData => cacheData.list));
|
||||
function sortServices(a, b) {
|
||||
return (b.isAdditionalCompletion ? -1 : 1) - (a.isAdditionalCompletion ? -1 : 1);
|
||||
}
|
||||
function combineCompletionList(lists) {
|
||||
return {
|
||||
isIncomplete: lists.some(list => list?.isIncomplete),
|
||||
itemDefaults: lists.find(list => list?.itemDefaults)?.itemDefaults,
|
||||
items: lists.map(list => list?.items ?? []).flat(),
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=provideCompletionItems.js.map
|
||||
5
node_modules/@volar/language-service/lib/features/provideDefinition.d.ts
generated
vendored
Normal file
5
node_modules/@volar/language-service/lib/features/provideDefinition.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { CodeInformation } from '@volar/language-core';
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
export declare function register(context: LanguageServiceContext, apiName: 'provideDeclaration' | 'provideDefinition' | 'provideTypeDefinition' | 'provideImplementation', isValidPosition: (data: CodeInformation) => boolean): (uri: URI, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.LocationLink[] | undefined>;
|
||||
125
node_modules/@volar/language-service/lib/features/provideDefinition.js
generated
vendored
Normal file
125
node_modules/@volar/language-service/lib/features/provideDefinition.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const dedupe = require("../utils/dedupe");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
function register(context, apiName, isValidPosition) {
|
||||
return (uri, position, token = cancellation_1.NoneCancellationToken) => {
|
||||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, docs => (0, featureWorkers_1.getGeneratedPositions)(docs, position, isValidPosition), async (plugin, document, position) => {
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
const recursiveChecker = dedupe.createLocationSet();
|
||||
const result = [];
|
||||
await withLinkedCode(document, position, undefined);
|
||||
return result;
|
||||
async function withLinkedCode(document, position, originDefinition) {
|
||||
const api = plugin[1][apiName];
|
||||
if (!api) {
|
||||
return;
|
||||
}
|
||||
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) {
|
||||
return;
|
||||
}
|
||||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
|
||||
const definitions = await api?.(document, position, token) ?? [];
|
||||
for (const definition of definitions) {
|
||||
let foundMirrorPosition = false;
|
||||
recursiveChecker.add({ uri: definition.targetUri, range: { start: definition.targetRange.start, end: definition.targetRange.start } });
|
||||
const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(definition.targetUri));
|
||||
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
||||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
||||
const linkedCodeMap = virtualCode && sourceScript
|
||||
? context.language.linkedCodeMaps.get(virtualCode)
|
||||
: undefined;
|
||||
if (sourceScript && virtualCode && linkedCodeMap) {
|
||||
const embeddedDocument = context.documents.get(context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id), virtualCode.languageId, virtualCode.snapshot);
|
||||
for (const linkedPos of (0, featureWorkers_1.getLinkedCodePositions)(embeddedDocument, linkedCodeMap, definition.targetSelectionRange.start)) {
|
||||
if (recursiveChecker.has({ uri: embeddedDocument.uri, range: { start: linkedPos, end: linkedPos } })) {
|
||||
continue;
|
||||
}
|
||||
foundMirrorPosition = true;
|
||||
await withLinkedCode(embeddedDocument, linkedPos, originDefinition ?? definition);
|
||||
}
|
||||
}
|
||||
if (!foundMirrorPosition) {
|
||||
if (originDefinition) {
|
||||
result.push({
|
||||
...definition,
|
||||
originSelectionRange: originDefinition.originSelectionRange,
|
||||
});
|
||||
}
|
||||
else {
|
||||
result.push(definition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, (data, map) => data.map(link => {
|
||||
if (link.originSelectionRange && map) {
|
||||
const originSelectionRange = toSourcePositionPreferSurroundedPosition(map, link.originSelectionRange, position);
|
||||
if (!originSelectionRange) {
|
||||
return;
|
||||
}
|
||||
link.originSelectionRange = originSelectionRange;
|
||||
}
|
||||
let foundTargetSelectionRange = false;
|
||||
const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(link.targetUri));
|
||||
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
||||
const targetVirtualFile = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
||||
if (sourceScript && targetVirtualFile) {
|
||||
const embeddedDocument = context.documents.get(context.encodeEmbeddedDocumentUri(sourceScript.id, targetVirtualFile.id), targetVirtualFile.languageId, targetVirtualFile.snapshot);
|
||||
for (const [targetScript, targetSourceMap] of context.language.maps.forEach(targetVirtualFile)) {
|
||||
const sourceDocument = context.documents.get(targetScript.id, targetScript.languageId, targetScript.snapshot);
|
||||
const docs = [sourceDocument, embeddedDocument, targetSourceMap];
|
||||
const targetSelectionRange = (0, featureWorkers_1.getSourceRange)(docs, link.targetSelectionRange);
|
||||
if (!targetSelectionRange) {
|
||||
continue;
|
||||
}
|
||||
foundTargetSelectionRange = true;
|
||||
let targetRange = (0, featureWorkers_1.getSourceRange)(docs, link.targetRange);
|
||||
link.targetUri = sourceDocument.uri;
|
||||
// loose range mapping to for template slots, slot properties
|
||||
link.targetRange = targetRange ?? targetSelectionRange;
|
||||
link.targetSelectionRange = targetSelectionRange;
|
||||
}
|
||||
if (apiName === 'provideDefinition' && !foundTargetSelectionRange) {
|
||||
for (const [targetScript] of context.language.maps.forEach(targetVirtualFile)) {
|
||||
if (targetScript.id.toString() !== uri.toString()) {
|
||||
return {
|
||||
...link,
|
||||
targetUri: targetScript.id.toString(),
|
||||
targetRange: {
|
||||
start: { line: 0, character: 0 },
|
||||
end: { line: 0, character: 0 },
|
||||
},
|
||||
targetSelectionRange: {
|
||||
start: { line: 0, character: 0 },
|
||||
end: { line: 0, character: 0 },
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
return link;
|
||||
}).filter(link => !!link), arr => dedupe.withLocationLinks(arr.flat()));
|
||||
};
|
||||
}
|
||||
function toSourcePositionPreferSurroundedPosition(docs, mappedRange, position) {
|
||||
let result;
|
||||
for (const range of (0, featureWorkers_1.getSourceRanges)(docs, mappedRange)) {
|
||||
if (!result) {
|
||||
result = range;
|
||||
}
|
||||
if ((range.start.line < position.line || (range.start.line === position.line && range.start.character <= position.character))
|
||||
&& (range.end.line > position.line || (range.end.line === position.line && range.end.character >= position.character))) {
|
||||
return range;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
//# sourceMappingURL=provideDefinition.js.map
|
||||
22
node_modules/@volar/language-service/lib/features/provideDiagnostics.d.ts
generated
vendored
Normal file
22
node_modules/@volar/language-service/lib/features/provideDiagnostics.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
import { DocumentsAndMap } from '../utils/featureWorkers';
|
||||
export interface ServiceDiagnosticData {
|
||||
uri: string;
|
||||
version: number;
|
||||
original: Pick<vscode.Diagnostic, 'data'>;
|
||||
isFormat: boolean;
|
||||
pluginIndex: number;
|
||||
documentUri: string;
|
||||
}
|
||||
export declare const errorMarkups: Map<URI, {
|
||||
error: vscode.Diagnostic;
|
||||
markup: vscode.MarkupContent;
|
||||
}[]>;
|
||||
export declare function register(context: LanguageServiceContext): (uri: URI, response?: (result: vscode.Diagnostic[]) => void, token?: vscode.CancellationToken) => Promise<vscode.Diagnostic[]>;
|
||||
export declare function transformDiagnostic(context: LanguageServiceContext, error: vscode.Diagnostic, docs: DocumentsAndMap | undefined): vscode.Diagnostic | undefined;
|
||||
export declare function updateRange(range: vscode.Range, change: {
|
||||
range: vscode.Range;
|
||||
newEnd: vscode.Position;
|
||||
}): vscode.Range | undefined;
|
||||
243
node_modules/@volar/language-service/lib/features/provideDiagnostics.js
generated
vendored
Normal file
243
node_modules/@volar/language-service/lib/features/provideDiagnostics.js
generated
vendored
Normal file
@@ -0,0 +1,243 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.errorMarkups = void 0;
|
||||
exports.register = register;
|
||||
exports.transformDiagnostic = transformDiagnostic;
|
||||
exports.updateRange = updateRange;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const common_1 = require("../utils/common");
|
||||
const dedupe = require("../utils/dedupe");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
const uriMap_1 = require("../utils/uriMap");
|
||||
exports.errorMarkups = (0, uriMap_1.createUriMap)();
|
||||
function register(context) {
|
||||
const lastResponses = (0, uriMap_1.createUriMap)();
|
||||
const cacheMaps = {
|
||||
semantic: new Map(),
|
||||
syntactic: new Map(),
|
||||
};
|
||||
context.env.onDidChangeConfiguration?.(() => {
|
||||
lastResponses.clear();
|
||||
cacheMaps.semantic.clear();
|
||||
cacheMaps.syntactic.clear();
|
||||
});
|
||||
return async (uri, response, token = cancellation_1.NoneCancellationToken) => {
|
||||
let langaugeIdAndSnapshot;
|
||||
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
||||
if (decoded) {
|
||||
langaugeIdAndSnapshot = context.language.scripts.get(decoded[0])?.generated?.embeddedCodes.get(decoded[1]);
|
||||
}
|
||||
else {
|
||||
langaugeIdAndSnapshot = context.language.scripts.get(uri);
|
||||
}
|
||||
if (!langaugeIdAndSnapshot) {
|
||||
return [];
|
||||
}
|
||||
const document = context.documents.get(uri, langaugeIdAndSnapshot.languageId, langaugeIdAndSnapshot.snapshot);
|
||||
const lastResponse = lastResponses.get(uri) ?? lastResponses.set(uri, {
|
||||
semantic: { errors: [] },
|
||||
syntactic: { errors: [] },
|
||||
}).get(uri);
|
||||
let updateCacheRangeFailed = false;
|
||||
let errorsUpdated = false;
|
||||
let lastCheckCancelAt = 0;
|
||||
for (const cache of Object.values(lastResponse)) {
|
||||
const oldSnapshot = cache.snapshot;
|
||||
const oldDocument = cache.document;
|
||||
const change = oldSnapshot ? langaugeIdAndSnapshot.snapshot.getChangeRange(oldSnapshot) : undefined;
|
||||
cache.snapshot = langaugeIdAndSnapshot.snapshot;
|
||||
cache.document = document;
|
||||
if (!updateCacheRangeFailed && oldDocument && change) {
|
||||
const changeRange = {
|
||||
range: {
|
||||
start: oldDocument.positionAt(change.span.start),
|
||||
end: oldDocument.positionAt(change.span.start + change.span.length),
|
||||
},
|
||||
newEnd: document.positionAt(change.span.start + change.newLength),
|
||||
};
|
||||
for (const error of cache.errors) {
|
||||
if (!updateRange(error.range, changeRange)) {
|
||||
updateCacheRangeFailed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await worker('syntactic', cacheMaps.syntactic, lastResponse.syntactic);
|
||||
processResponse();
|
||||
await worker('semantic', cacheMaps.semantic, lastResponse.semantic);
|
||||
return collectErrors();
|
||||
function processResponse() {
|
||||
if (errorsUpdated && !updateCacheRangeFailed) {
|
||||
response?.(collectErrors());
|
||||
errorsUpdated = false;
|
||||
}
|
||||
}
|
||||
function collectErrors() {
|
||||
return Object.values(lastResponse).flatMap(({ errors }) => errors);
|
||||
}
|
||||
async function worker(kind, cacheMap, cache) {
|
||||
const result = await (0, featureWorkers_1.documentFeatureWorker)(context, uri, docs => docs[2].mappings.some(mapping => (0, language_core_1.isDiagnosticsEnabled)(mapping.data)), async (plugin, document) => {
|
||||
const interFileDependencies = plugin[0].capabilities.diagnosticProvider?.interFileDependencies;
|
||||
if (kind === 'semantic' !== interFileDependencies) {
|
||||
return;
|
||||
}
|
||||
if (Date.now() - lastCheckCancelAt >= 10) {
|
||||
await (0, common_1.sleep)(10); // waiting LSP event polling
|
||||
lastCheckCancelAt = Date.now();
|
||||
}
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
const pluginIndex = context.plugins.indexOf(plugin);
|
||||
const pluginCache = cacheMap.get(pluginIndex) ?? cacheMap.set(pluginIndex, new Map()).get(pluginIndex);
|
||||
const cache = pluginCache.get(document.uri);
|
||||
if (!interFileDependencies && cache && cache.documentVersion === document.version) {
|
||||
return cache.errors;
|
||||
}
|
||||
const errors = await plugin[1].provideDiagnostics?.(document, token) || [];
|
||||
errors.forEach(error => {
|
||||
error.data = {
|
||||
uri: uri.toString(),
|
||||
version: document.version,
|
||||
pluginIndex: pluginIndex,
|
||||
isFormat: false,
|
||||
original: {
|
||||
data: error.data,
|
||||
},
|
||||
documentUri: document.uri,
|
||||
};
|
||||
});
|
||||
errorsUpdated = true;
|
||||
pluginCache.set(document.uri, {
|
||||
documentVersion: document.version,
|
||||
errors,
|
||||
});
|
||||
return errors;
|
||||
}, (errors, map) => {
|
||||
return errors
|
||||
.map(error => transformDiagnostic(context, error, map))
|
||||
.filter(error => !!error);
|
||||
}, arr => dedupe.withDiagnostics(arr.flat()));
|
||||
if (result) {
|
||||
cache.errors = result;
|
||||
cache.snapshot = langaugeIdAndSnapshot?.snapshot;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function transformDiagnostic(context, error, docs) {
|
||||
// clone it to avoid modify cache
|
||||
let _error = { ...error };
|
||||
if (docs) {
|
||||
const range = (0, featureWorkers_1.getSourceRange)(docs, error.range, data => (0, language_core_1.shouldReportDiagnostics)(data, error.source, error.code));
|
||||
if (!range) {
|
||||
return;
|
||||
}
|
||||
_error.range = range;
|
||||
}
|
||||
if (_error.relatedInformation) {
|
||||
const relatedInfos = [];
|
||||
for (const info of _error.relatedInformation) {
|
||||
const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(info.location.uri));
|
||||
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
||||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
||||
if (sourceScript && virtualCode) {
|
||||
const embeddedDocument = context.documents.get(context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id), virtualCode.languageId, virtualCode.snapshot);
|
||||
for (const [sourceScript, map] of context.language.maps.forEach(virtualCode)) {
|
||||
const sourceDocument = context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot);
|
||||
const docs = [sourceDocument, embeddedDocument, map];
|
||||
const range = (0, featureWorkers_1.getSourceRange)(docs, info.location.range, data => (0, language_core_1.shouldReportDiagnostics)(data, undefined, undefined));
|
||||
if (range) {
|
||||
relatedInfos.push({
|
||||
location: {
|
||||
uri: sourceDocument.uri,
|
||||
range,
|
||||
},
|
||||
message: info.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
relatedInfos.push(info);
|
||||
}
|
||||
}
|
||||
_error.relatedInformation = relatedInfos;
|
||||
}
|
||||
return _error;
|
||||
}
|
||||
function updateRange(range, change) {
|
||||
if (!updatePosition(range.start, change, false)) {
|
||||
return;
|
||||
}
|
||||
if (!updatePosition(range.end, change, true)) {
|
||||
return;
|
||||
}
|
||||
if (range.end.line === range.start.line && range.end.character <= range.start.character) {
|
||||
range.end.character++;
|
||||
}
|
||||
return range;
|
||||
}
|
||||
function updatePosition(position, change, isEnd) {
|
||||
if (change.range.end.line > position.line) {
|
||||
if (change.newEnd.line > position.line) {
|
||||
// No change
|
||||
return true;
|
||||
}
|
||||
else if (change.newEnd.line === position.line) {
|
||||
position.character = Math.min(position.character, change.newEnd.character);
|
||||
return true;
|
||||
}
|
||||
else if (change.newEnd.line < position.line) {
|
||||
position.line = change.newEnd.line;
|
||||
position.character = change.newEnd.character;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (change.range.end.line === position.line) {
|
||||
const characterDiff = change.newEnd.character - change.range.end.character;
|
||||
if (position.character >= change.range.end.character) {
|
||||
if (change.newEnd.line !== change.range.end.line) {
|
||||
position.line = change.newEnd.line;
|
||||
position.character = change.newEnd.character + position.character - change.range.end.character;
|
||||
}
|
||||
else {
|
||||
if (isEnd ? change.range.end.character < position.character : change.range.end.character <= position.character) {
|
||||
position.character += characterDiff;
|
||||
}
|
||||
else {
|
||||
const offset = change.range.end.character - position.character;
|
||||
if (-characterDiff > offset) {
|
||||
position.character += characterDiff + offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if (change.newEnd.line === change.range.end.line) {
|
||||
const offset = change.range.end.character - position.character;
|
||||
if (-characterDiff > offset) {
|
||||
position.character += characterDiff + offset;
|
||||
}
|
||||
}
|
||||
else if (change.newEnd.line < change.range.end.line) {
|
||||
position.line = change.newEnd.line;
|
||||
position.character = change.newEnd.character;
|
||||
}
|
||||
else {
|
||||
// No change
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (change.range.end.line < position.line) {
|
||||
position.line += change.newEnd.line - change.range.end.line;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//# sourceMappingURL=provideDiagnostics.js.map
|
||||
4
node_modules/@volar/language-service/lib/features/provideDocumentColors.d.ts
generated
vendored
Normal file
4
node_modules/@volar/language-service/lib/features/provideDocumentColors.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
export declare function register(context: LanguageServiceContext): (uri: URI, token?: vscode.CancellationToken) => Promise<vscode.ColorInformation[] | undefined>;
|
||||
32
node_modules/@volar/language-service/lib/features/provideDocumentColors.js
generated
vendored
Normal file
32
node_modules/@volar/language-service/lib/features/provideDocumentColors.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
function register(context) {
|
||||
return (uri, token = cancellation_1.NoneCancellationToken) => {
|
||||
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, docs => docs[2].mappings.some(mapping => (0, language_core_1.isColorEnabled)(mapping.data)), (plugin, document) => {
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
return plugin[1].provideDocumentColors?.(document, token);
|
||||
}, (data, docs) => {
|
||||
if (!docs) {
|
||||
return data;
|
||||
}
|
||||
return data
|
||||
.map(color => {
|
||||
const range = (0, featureWorkers_1.getSourceRange)(docs, color.range, language_core_1.isColorEnabled);
|
||||
if (range) {
|
||||
return {
|
||||
range,
|
||||
color: color.color,
|
||||
};
|
||||
}
|
||||
})
|
||||
.filter(color => !!color);
|
||||
}, arr => arr.flat());
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=provideDocumentColors.js.map
|
||||
4
node_modules/@volar/language-service/lib/features/provideDocumentDropEdits.d.ts
generated
vendored
Normal file
4
node_modules/@volar/language-service/lib/features/provideDocumentDropEdits.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { DataTransferItem, LanguageServiceContext } from '../types';
|
||||
export declare function register(context: LanguageServiceContext): (uri: URI, position: vscode.Position, dataTransfer: Map<string, DataTransferItem>, token?: vscode.CancellationToken) => Promise<import("../types").DocumentDropEdit | undefined>;
|
||||
26
node_modules/@volar/language-service/lib/features/provideDocumentDropEdits.js
generated
vendored
Normal file
26
node_modules/@volar/language-service/lib/features/provideDocumentDropEdits.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
const transform_1 = require("../utils/transform");
|
||||
function register(context) {
|
||||
return (uri, position, dataTransfer, token = cancellation_1.NoneCancellationToken) => {
|
||||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, function* (docs) {
|
||||
for (const mappedPosition of (0, featureWorkers_1.getGeneratedPositions)(docs, position)) {
|
||||
yield mappedPosition;
|
||||
}
|
||||
}, (plugin, document, arg) => {
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
return plugin[1].provideDocumentDropEdits?.(document, arg, dataTransfer, token);
|
||||
}, edit => {
|
||||
if (edit.additionalEdit) {
|
||||
edit.additionalEdit = (0, transform_1.transformWorkspaceEdit)(edit.additionalEdit, context, undefined);
|
||||
}
|
||||
return edit;
|
||||
});
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=provideDocumentDropEdits.js.map
|
||||
7
node_modules/@volar/language-service/lib/features/provideDocumentFormattingEdits.d.ts
generated
vendored
Normal file
7
node_modules/@volar/language-service/lib/features/provideDocumentFormattingEdits.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
export declare function register(context: LanguageServiceContext): (uri: URI, options: vscode.FormattingOptions, range: vscode.Range | undefined, onTypeParams: {
|
||||
ch: string;
|
||||
position: vscode.Position;
|
||||
} | undefined, token?: vscode.CancellationToken) => Promise<vscode.TextEdit[] | undefined>;
|
||||
226
node_modules/@volar/language-service/lib/features/provideDocumentFormattingEdits.js
generated
vendored
Normal file
226
node_modules/@volar/language-service/lib/features/provideDocumentFormattingEdits.js
generated
vendored
Normal file
@@ -0,0 +1,226 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const common_1 = require("../utils/common");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
function register(context) {
|
||||
return async (uri, options, range, onTypeParams, token = cancellation_1.NoneCancellationToken) => {
|
||||
const sourceScript = context.language.scripts.get(uri);
|
||||
if (!sourceScript) {
|
||||
return;
|
||||
}
|
||||
let document = context.documents.get(uri, sourceScript.languageId, sourceScript.snapshot);
|
||||
range ??= {
|
||||
start: document.positionAt(0),
|
||||
end: document.positionAt(document.getText().length),
|
||||
};
|
||||
if (!sourceScript.generated) {
|
||||
return onTypeParams
|
||||
? (await tryFormat(document, document, sourceScript, undefined, 0, onTypeParams.position, onTypeParams.ch))?.edits
|
||||
: (await tryFormat(document, document, sourceScript, undefined, 0, range, undefined))?.edits;
|
||||
}
|
||||
const embeddedRanges = new Map(); // TODO: Formatting of upper-level virtual code may cause offset of lower-level selection range
|
||||
const startOffset = document.offsetAt(range.start);
|
||||
const endOffset = document.offsetAt(range.end);
|
||||
for (const code of (0, language_core_1.forEachEmbeddedCode)(sourceScript.generated.root)) {
|
||||
const map = context.language.maps.get(code, sourceScript);
|
||||
if (map) {
|
||||
const embeddedRange = (0, common_1.findOverlapCodeRange)(startOffset, endOffset, map, language_core_1.isFormattingEnabled);
|
||||
if (embeddedRange) {
|
||||
if (embeddedRange.start === map.mappings[0].generatedOffsets[0]) {
|
||||
embeddedRange.start = 0;
|
||||
}
|
||||
const lastMapping = map.mappings[map.mappings.length - 1];
|
||||
if (embeddedRange.end === lastMapping.generatedOffsets[lastMapping.generatedOffsets.length - 1] + (lastMapping.generatedLengths ?? lastMapping.lengths)[lastMapping.lengths.length - 1]) {
|
||||
embeddedRange.end = code.snapshot.getLength();
|
||||
}
|
||||
embeddedRanges.set(code.id, embeddedRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
const originalDocument = document;
|
||||
let tempSourceSnapshot = sourceScript.snapshot;
|
||||
let tempVirtualFile = context.language.scripts.set(vscode_uri_1.URI.parse(sourceScript.id.toString() + '.tmp'), sourceScript.snapshot, sourceScript.languageId, [sourceScript.generated.languagePlugin])?.generated?.root;
|
||||
if (!tempVirtualFile) {
|
||||
return;
|
||||
}
|
||||
let currentCodes = [];
|
||||
for (let depth = 0; (currentCodes = getNestedEmbeddedFiles(context, sourceScript.id, tempVirtualFile, depth)).length > 0; depth++) {
|
||||
let edits = [];
|
||||
for (const code of currentCodes) {
|
||||
if (!code.mappings.some(mapping => (0, language_core_1.isFormattingEnabled)(mapping.data))) {
|
||||
continue;
|
||||
}
|
||||
const currentRange = embeddedRanges.get(code.id);
|
||||
if (!currentRange) {
|
||||
continue;
|
||||
}
|
||||
const isChildRange = [...(0, language_core_1.forEachEmbeddedCode)(code)].some(child => {
|
||||
if (child === code) {
|
||||
return false;
|
||||
}
|
||||
const childRange = embeddedRanges.get(child.id);
|
||||
return childRange && childRange.end - childRange.start >= currentRange.end - currentRange.start;
|
||||
});
|
||||
if (isChildRange) {
|
||||
continue;
|
||||
}
|
||||
const docs = [
|
||||
context.documents.get(uri, sourceScript.languageId, tempSourceSnapshot),
|
||||
context.documents.get(context.encodeEmbeddedDocumentUri(uri, code.id), code.languageId, code.snapshot),
|
||||
context.language.mapperFactory(code.mappings),
|
||||
];
|
||||
let embeddedResult;
|
||||
if (onTypeParams) {
|
||||
for (const embeddedPosition of (0, featureWorkers_1.getGeneratedPositions)(docs, onTypeParams.position)) {
|
||||
embeddedResult = await tryFormat(docs[0], docs[1], sourceScript, code, depth, embeddedPosition, onTypeParams.ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (currentRange) {
|
||||
embeddedResult = await tryFormat(docs[0], docs[1], sourceScript, code, depth, {
|
||||
start: docs[1].positionAt(currentRange.start),
|
||||
end: docs[1].positionAt(currentRange.end),
|
||||
});
|
||||
}
|
||||
if (!embeddedResult) {
|
||||
continue;
|
||||
}
|
||||
for (const textEdit of embeddedResult.edits) {
|
||||
const range = (0, featureWorkers_1.getSourceRange)(docs, textEdit.range);
|
||||
if (range) {
|
||||
edits.push({
|
||||
newText: textEdit.newText,
|
||||
range,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (edits.length > 0) {
|
||||
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
||||
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
||||
tempSourceSnapshot = (0, common_1.stringToSnapshot)(newText);
|
||||
tempVirtualFile = context.language.scripts.set(vscode_uri_1.URI.parse(sourceScript.id.toString() + '.tmp'), tempSourceSnapshot, sourceScript.languageId, [sourceScript.generated.languagePlugin])?.generated?.root;
|
||||
if (!tempVirtualFile) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (document.getText() === originalDocument.getText()) {
|
||||
return;
|
||||
}
|
||||
const editRange = {
|
||||
start: originalDocument.positionAt(0),
|
||||
end: originalDocument.positionAt(originalDocument.getText().length),
|
||||
};
|
||||
const textEdit = {
|
||||
range: editRange,
|
||||
newText: document.getText(),
|
||||
};
|
||||
return [textEdit];
|
||||
}
|
||||
finally {
|
||||
context.language.scripts.delete(vscode_uri_1.URI.parse(sourceScript.id.toString() + '.tmp'));
|
||||
}
|
||||
async function tryFormat(sourceDocument, document, sourceScript, virtualCode, embeddedLevel, rangeOrPosition, ch) {
|
||||
if (context.disabledEmbeddedDocumentUris.get(vscode_uri_1.URI.parse(document.uri))) {
|
||||
return;
|
||||
}
|
||||
let codeOptions;
|
||||
rangeOrPosition ??= {
|
||||
start: document.positionAt(0),
|
||||
end: document.positionAt(document.getText().length),
|
||||
};
|
||||
if (virtualCode) {
|
||||
codeOptions = {
|
||||
level: embeddedLevel,
|
||||
initialIndentLevel: 0,
|
||||
};
|
||||
if (virtualCode.mappings.length) {
|
||||
const firstMapping = virtualCode.mappings[0];
|
||||
const startOffset = firstMapping.sourceOffsets[0];
|
||||
const startPosition = sourceDocument.positionAt(startOffset);
|
||||
codeOptions.initialIndentLevel = computeInitialIndent(sourceDocument.getText(), sourceDocument.offsetAt({ line: startPosition.line, character: 0 }), options);
|
||||
}
|
||||
for (const plugin of context.plugins) {
|
||||
if (context.disabledServicePlugins.has(plugin[1])) {
|
||||
continue;
|
||||
}
|
||||
codeOptions = await plugin[1].resolveEmbeddedCodeFormattingOptions?.(sourceScript, virtualCode, codeOptions, token) ?? codeOptions;
|
||||
}
|
||||
}
|
||||
for (const plugin of context.plugins) {
|
||||
if (context.disabledServicePlugins.has(plugin[1])) {
|
||||
continue;
|
||||
}
|
||||
if (token.isCancellationRequested) {
|
||||
break;
|
||||
}
|
||||
let edits;
|
||||
try {
|
||||
if (ch !== undefined && rangeOrPosition && 'line' in rangeOrPosition && 'character' in rangeOrPosition) {
|
||||
if (plugin[0].capabilities.documentOnTypeFormattingProvider?.triggerCharacters?.includes(ch)) {
|
||||
edits = await plugin[1].provideOnTypeFormattingEdits?.(document, rangeOrPosition, ch, options, codeOptions, token);
|
||||
}
|
||||
}
|
||||
else if (ch === undefined && rangeOrPosition && 'start' in rangeOrPosition && 'end' in rangeOrPosition) {
|
||||
edits = await plugin[1].provideDocumentFormattingEdits?.(document, rangeOrPosition, options, codeOptions, token);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.warn(err);
|
||||
}
|
||||
if (!edits) {
|
||||
continue;
|
||||
}
|
||||
return {
|
||||
plugin,
|
||||
edits,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function getNestedEmbeddedFiles(context, uri, rootCode, depth) {
|
||||
const nestedCodesByLevel = [[rootCode]];
|
||||
while (true) {
|
||||
if (nestedCodesByLevel.length > depth) {
|
||||
return nestedCodesByLevel[depth];
|
||||
}
|
||||
const nestedCodes = [];
|
||||
for (const code of nestedCodesByLevel[nestedCodesByLevel.length - 1]) {
|
||||
if (code.embeddedCodes) {
|
||||
for (const embedded of code.embeddedCodes) {
|
||||
if (!context.disabledEmbeddedDocumentUris.get(context.encodeEmbeddedDocumentUri(uri, embedded.id))) {
|
||||
nestedCodes.push(embedded);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
nestedCodesByLevel.push(nestedCodes);
|
||||
}
|
||||
}
|
||||
function computeInitialIndent(content, i, options) {
|
||||
let nChars = 0;
|
||||
const tabSize = options.tabSize || 4;
|
||||
while (i < content.length) {
|
||||
const ch = content.charAt(i);
|
||||
if (ch === ' ') {
|
||||
nChars++;
|
||||
}
|
||||
else if (ch === '\t') {
|
||||
nChars += tabSize;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return Math.floor(nChars / tabSize);
|
||||
}
|
||||
//# sourceMappingURL=provideDocumentFormattingEdits.js.map
|
||||
4
node_modules/@volar/language-service/lib/features/provideDocumentHighlights.d.ts
generated
vendored
Normal file
4
node_modules/@volar/language-service/lib/features/provideDocumentHighlights.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
export declare function register(context: LanguageServiceContext): (uri: URI, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.DocumentHighlight[] | undefined>;
|
||||
68
node_modules/@volar/language-service/lib/features/provideDocumentHighlights.js
generated
vendored
Normal file
68
node_modules/@volar/language-service/lib/features/provideDocumentHighlights.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const vscode_uri_1 = require("vscode-uri");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const dedupe = require("../utils/dedupe");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
function register(context) {
|
||||
return (uri, position, token = cancellation_1.NoneCancellationToken) => {
|
||||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, docs => (0, featureWorkers_1.getGeneratedPositions)(docs, position, language_core_1.isHighlightEnabled), async (plugin, document, position) => {
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
const recursiveChecker = dedupe.createLocationSet();
|
||||
const result = [];
|
||||
await withLinkedCode(document, position);
|
||||
return result;
|
||||
async function withLinkedCode(document, position) {
|
||||
if (!plugin[1].provideDocumentHighlights) {
|
||||
return;
|
||||
}
|
||||
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) {
|
||||
return;
|
||||
}
|
||||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } });
|
||||
const references = await plugin[1].provideDocumentHighlights(document, position, token) ?? [];
|
||||
for (const reference of references) {
|
||||
let foundMirrorPosition = false;
|
||||
recursiveChecker.add({ uri: document.uri, range: { start: reference.range.start, end: reference.range.start } });
|
||||
const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(document.uri));
|
||||
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
||||
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
||||
const linkedCodeMap = virtualCode && sourceScript
|
||||
? context.language.linkedCodeMaps.get(virtualCode)
|
||||
: undefined;
|
||||
if (sourceScript && virtualCode && linkedCodeMap) {
|
||||
const embeddedDocument = context.documents.get(context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id), virtualCode.languageId, virtualCode.snapshot);
|
||||
for (const linkedPos of (0, featureWorkers_1.getLinkedCodePositions)(embeddedDocument, linkedCodeMap, reference.range.start)) {
|
||||
if (recursiveChecker.has({ uri: embeddedDocument.uri, range: { start: linkedPos, end: linkedPos } })) {
|
||||
continue;
|
||||
}
|
||||
foundMirrorPosition = true;
|
||||
await withLinkedCode(embeddedDocument, linkedPos);
|
||||
}
|
||||
}
|
||||
if (!foundMirrorPosition) {
|
||||
result.push(reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, (data, docs) => data
|
||||
.map(highlight => {
|
||||
if (!docs) {
|
||||
return highlight;
|
||||
}
|
||||
const range = (0, featureWorkers_1.getSourceRange)(docs, highlight.range, language_core_1.isHighlightEnabled);
|
||||
if (range) {
|
||||
return {
|
||||
...highlight,
|
||||
range,
|
||||
};
|
||||
}
|
||||
})
|
||||
.filter(highlight => !!highlight), arr => arr.flat());
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=provideDocumentHighlights.js.map
|
||||
9
node_modules/@volar/language-service/lib/features/provideDocumentLinks.d.ts
generated
vendored
Normal file
9
node_modules/@volar/language-service/lib/features/provideDocumentLinks.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
export interface DocumentLinkData {
|
||||
uri: string;
|
||||
original: Pick<vscode.DocumentLink, 'data'>;
|
||||
pluginIndex: number;
|
||||
}
|
||||
export declare function register(context: LanguageServiceContext): (uri: URI, token?: vscode.CancellationToken) => Promise<vscode.DocumentLink[]>;
|
||||
53
node_modules/@volar/language-service/lib/features/provideDocumentLinks.js
generated
vendored
Normal file
53
node_modules/@volar/language-service/lib/features/provideDocumentLinks.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
const transform_1 = require("../utils/transform");
|
||||
function register(context) {
|
||||
return async (uri, token = cancellation_1.NoneCancellationToken) => {
|
||||
return await (0, featureWorkers_1.documentFeatureWorker)(context, uri, docs => docs[2].mappings.some(mapping => (0, language_core_1.isDocumentLinkEnabled)(mapping.data)), async (plugin, document) => {
|
||||
if (token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
const links = await plugin[1].provideDocumentLinks?.(document, token);
|
||||
for (const link of links ?? []) {
|
||||
if (plugin[1].resolveDocumentLink) {
|
||||
link.data = {
|
||||
uri: uri.toString(),
|
||||
original: {
|
||||
data: link.data,
|
||||
},
|
||||
pluginIndex: context.plugins.indexOf(plugin),
|
||||
};
|
||||
}
|
||||
else {
|
||||
delete link.data;
|
||||
}
|
||||
}
|
||||
return links;
|
||||
}, (links, docs) => {
|
||||
if (!docs) {
|
||||
return links;
|
||||
}
|
||||
return links
|
||||
.map(link => {
|
||||
const range = (0, featureWorkers_1.getSourceRange)(docs, link.range, language_core_1.isDocumentLinkEnabled);
|
||||
if (!range) {
|
||||
return;
|
||||
}
|
||||
link = {
|
||||
...link,
|
||||
range,
|
||||
};
|
||||
if (link.target) {
|
||||
link.target = (0, transform_1.transformDocumentLinkTarget)(link.target, context).toString();
|
||||
}
|
||||
return link;
|
||||
})
|
||||
.filter(link => !!link);
|
||||
}, arr => arr.flat()) ?? [];
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=provideDocumentLinks.js.map
|
||||
4
node_modules/@volar/language-service/lib/features/provideDocumentSemanticTokens.d.ts
generated
vendored
Normal file
4
node_modules/@volar/language-service/lib/features/provideDocumentSemanticTokens.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type * as vscode from 'vscode-languageserver-protocol';
|
||||
import { URI } from 'vscode-uri';
|
||||
import type { LanguageServiceContext } from '../types';
|
||||
export declare function register(context: LanguageServiceContext): (uri: URI, range: vscode.Range | undefined, legend: vscode.SemanticTokensLegend, _reportProgress?: (tokens: vscode.SemanticTokens) => void, token?: vscode.CancellationToken) => Promise<vscode.SemanticTokens | undefined>;
|
||||
67
node_modules/@volar/language-service/lib/features/provideDocumentSemanticTokens.js
generated
vendored
Normal file
67
node_modules/@volar/language-service/lib/features/provideDocumentSemanticTokens.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.register = register;
|
||||
const language_core_1 = require("@volar/language-core");
|
||||
const SemanticTokensBuilder_1 = require("../utils/SemanticTokensBuilder");
|
||||
const cancellation_1 = require("../utils/cancellation");
|
||||
const common_1 = require("../utils/common");
|
||||
const featureWorkers_1 = require("../utils/featureWorkers");
|
||||
function register(context) {
|
||||
return async (uri, range, legend, _reportProgress, // TODO
|
||||
token = cancellation_1.NoneCancellationToken) => {
|
||||
const sourceScript = context.language.scripts.get(uri);
|
||||
if (!sourceScript) {
|
||||
return;
|
||||
}
|
||||
const document = context.documents.get(uri, sourceScript.languageId, sourceScript.snapshot);
|
||||
if (!range) {
|
||||
range = {
|
||||
start: { line: 0, character: 0 },
|
||||
end: { line: document.lineCount - 1, character: document.getText().length },
|
||||
};
|
||||
}
|
||||
const tokens = await (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => range, function* (docs) {
|
||||
const mapped = (0, common_1.findOverlapCodeRange)(docs[0].offsetAt(range.start), docs[0].offsetAt(range.end), docs[2], language_core_1.isSemanticTokensEnabled);
|
||||
if (mapped) {
|
||||
yield {
|
||||
start: docs[1].positionAt(mapped.start),
|
||||
end: docs[1].positionAt(mapped.end),
|
||||
};
|
||||
}
|
||||
}, (plugin, document, range) => {
|
||||
if (token?.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
return plugin[1].provideDocumentSemanticTokens?.(document, range, legend, token);
|
||||
}, (tokens, docs) => {
|
||||
if (!docs) {
|
||||
return tokens;
|
||||
}
|
||||
return tokens
|
||||
.map(_token => {
|
||||
const range = (0, featureWorkers_1.getSourceRange)(docs, {
|
||||
start: { line: _token[0], character: _token[1] },
|
||||
end: { line: _token[0], character: _token[1] + _token[2] },
|
||||
}, language_core_1.isSemanticTokensEnabled);
|
||||
if (range) {
|
||||
return [range.start.line, range.start.character, range.end.character - range.start.character, _token[3], _token[4]];
|
||||
}
|
||||
})
|
||||
.filter(token => !!token);
|
||||
}, tokens => tokens.flat()
|
||||
// tokens => reportProgress?.(buildTokens(tokens)), // TODO: this has no effect with LSP
|
||||
);
|
||||
if (tokens) {
|
||||
return buildTokens(tokens);
|
||||
}
|
||||
};
|
||||
}
|
||||
function buildTokens(tokens) {
|
||||
const builder = new SemanticTokensBuilder_1.SemanticTokensBuilder();
|
||||
const sortedTokens = tokens.sort((a, b) => a[0] - b[0] === 0 ? a[1] - b[1] : a[0] - b[0]);
|
||||
for (const token of sortedTokens) {
|
||||
builder.push(...token);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
//# sourceMappingURL=provideDocumentSemanticTokens.js.map
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user