@volar/language-server
Advanced tools
Comparing version 1.0.12 to 1.0.13
@@ -15,2 +15,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -24,2 +33,3 @@ exports.createLanguageServer = void 0; | ||
const webFileSystemHost_1 = require("./utils/webFileSystemHost"); | ||
const shared = require("@volar/shared"); | ||
function createLanguageServer(plugins) { | ||
@@ -33,4 +43,11 @@ const messageReader = new vscode.BrowserMessageReader(self); | ||
}, | ||
loadTypescriptLocalized() { | ||
// TODO | ||
loadTypescriptLocalized(tsdk, locale) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const uri = shared.getUriByPath(`${tsdk}/${locale}/diagnosticMessages.generated.json`); | ||
const json = yield (0, http_1.default)(uri); | ||
return JSON.parse(json); | ||
} | ||
catch (_a) { } | ||
}); | ||
}, | ||
@@ -37,0 +54,0 @@ schemaRequestHandlers: { |
@@ -71,6 +71,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const project = (yield projects.getProject(params.uri)); | ||
if (project) { | ||
return { | ||
fileName: project.tsconfig, | ||
}; | ||
if (project === null || project === void 0 ? void 0 : project.tsconfig) { | ||
return { uri: shared.getUriByPath(project.tsconfig) }; | ||
} | ||
@@ -77,0 +75,0 @@ })); |
@@ -15,2 +15,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -40,7 +49,9 @@ exports.createLanguageServer = void 0; | ||
loadTypescriptLocalized(tsdk, locale) { | ||
try { | ||
const path = require.resolve(`./${locale}/diagnosticMessages.generated.json`, { paths: [tsdk] }); | ||
return require(path); | ||
} | ||
catch (_a) { } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const path = require.resolve(`./${locale}/diagnosticMessages.generated.json`, { paths: [tsdk] }); | ||
return require(path); | ||
} | ||
catch (_a) { } | ||
}); | ||
}, | ||
@@ -47,0 +58,0 @@ schemaRequestHandlers: { |
@@ -12,2 +12,11 @@ import * as vscode from 'vscode-languageserver-protocol'; | ||
} | ||
export declare namespace FsStatRequest { | ||
const type: vscode.RequestType<string, html.FileStat | null | undefined, unknown>; | ||
} | ||
export declare namespace FsReadFileRequest { | ||
const type: vscode.RequestType<string, string | null | undefined, unknown>; | ||
} | ||
export declare namespace FsReadDirectoryRequest { | ||
const type: vscode.RequestType<string, [string, html.FileType][], unknown>; | ||
} | ||
/** | ||
@@ -27,3 +36,3 @@ * Client request server | ||
type ResponseType = { | ||
fileName: string; | ||
uri: string; | ||
} | null | undefined; | ||
@@ -82,13 +91,1 @@ type ErrorType = never; | ||
} | ||
/** | ||
* FS request for browser | ||
*/ | ||
export declare namespace FsStatRequest { | ||
const type: vscode.RequestType<string, html.FileStat | undefined, unknown>; | ||
} | ||
export declare namespace FsReadFileRequest { | ||
const type: vscode.RequestType<string, string | undefined, unknown>; | ||
} | ||
export declare namespace FsReadDirectoryRequest { | ||
const type: vscode.RequestType<string, [string, html.FileType][], unknown>; | ||
} |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FsReadDirectoryRequest = exports.FsReadFileRequest = exports.FsStatRequest = exports.ReportStats = exports.GetVirtualFileRequest = exports.GetVirtualFileNamesRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.VerifyAllScriptsNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = exports.ShowReferencesNotification = void 0; | ||
exports.ReportStats = exports.GetVirtualFileRequest = exports.GetVirtualFileNamesRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.VerifyAllScriptsNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = exports.FsReadDirectoryRequest = exports.FsReadFileRequest = exports.FsStatRequest = exports.ShowReferencesNotification = void 0; | ||
const vscode = require("vscode-languageserver-protocol"); | ||
@@ -11,2 +11,14 @@ /** | ||
})(ShowReferencesNotification = exports.ShowReferencesNotification || (exports.ShowReferencesNotification = {})); | ||
var FsStatRequest; | ||
(function (FsStatRequest) { | ||
FsStatRequest.type = new vscode.RequestType('fs/stat'); | ||
})(FsStatRequest = exports.FsStatRequest || (exports.FsStatRequest = {})); | ||
var FsReadFileRequest; | ||
(function (FsReadFileRequest) { | ||
FsReadFileRequest.type = new vscode.RequestType('fs/readFile'); | ||
})(FsReadFileRequest = exports.FsReadFileRequest || (exports.FsReadFileRequest = {})); | ||
var FsReadDirectoryRequest; | ||
(function (FsReadDirectoryRequest) { | ||
FsReadDirectoryRequest.type = new vscode.RequestType('fs/readDirectory'); | ||
})(FsReadDirectoryRequest = exports.FsReadDirectoryRequest || (exports.FsReadDirectoryRequest = {})); | ||
/** | ||
@@ -51,17 +63,2 @@ * Client request server | ||
})(ReportStats = exports.ReportStats || (exports.ReportStats = {})); | ||
/** | ||
* FS request for browser | ||
*/ | ||
var FsStatRequest; | ||
(function (FsStatRequest) { | ||
FsStatRequest.type = new vscode.RequestType('fs/stat'); | ||
})(FsStatRequest = exports.FsStatRequest || (exports.FsStatRequest = {})); | ||
var FsReadFileRequest; | ||
(function (FsReadFileRequest) { | ||
FsReadFileRequest.type = new vscode.RequestType('fs/readFile'); | ||
})(FsReadFileRequest = exports.FsReadFileRequest || (exports.FsReadFileRequest = {})); | ||
var FsReadDirectoryRequest; | ||
(function (FsReadDirectoryRequest) { | ||
FsReadDirectoryRequest.type = new vscode.RequestType('fs/readDirectory'); | ||
})(FsReadDirectoryRequest = exports.FsReadDirectoryRequest || (exports.FsReadDirectoryRequest = {})); | ||
//# sourceMappingURL=protocol.js.map |
@@ -129,3 +129,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
fsHost = runtimeEnv.createFileSystemHost(ts, params.capabilities); | ||
const tsLocalized = params.locale ? runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, params.locale) : undefined; | ||
const tsLocalized = params.locale ? yield runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, params.locale) : undefined; | ||
const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName); | ||
@@ -132,0 +132,0 @@ const _projects = (0, workspaces_1.createWorkspaces)(runtimeEnv, plugins, fsHost, configHost, ts, tsLocalized, params.capabilities, options, documents, connection, cancelTokenHost); |
@@ -14,3 +14,3 @@ /// <reference types="node" /> | ||
getWorkspaceFileSystem(rootUri: URI): FileSystem; | ||
onDidChangeWatchedFiles(cb: (params: vscode.DidChangeWatchedFilesParams, reason: 'lsp' | 'web-cache-updated') => void): () => void; | ||
onDidChangeWatchedFiles(cb: (params: vscode.DidChangeWatchedFilesParams) => void): () => void; | ||
}; | ||
@@ -20,3 +20,3 @@ export type FileSystem = Pick<ts.System, 'newLine' | 'useCaseSensitiveFileNames' | 'fileExists' | 'readFile' | 'readDirectory' | 'getCurrentDirectory' | 'realpath' | 'resolvePath'> & Partial<ts.System>; | ||
loadTypescript: (tsdk: string) => typeof import('typescript/lib/tsserverlibrary'); | ||
loadTypescriptLocalized: (tsdk: string, locale: string) => any; | ||
loadTypescriptLocalized: (tsdk: string, locale: string) => Promise<{} | undefined>; | ||
schemaRequestHandlers: { | ||
@@ -23,0 +23,0 @@ [schema: string]: (uri: string, encoding?: BufferEncoding) => Promise<string>; |
@@ -13,2 +13,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
const config = require(configPath); | ||
delete require.cache[configPath]; | ||
return (_a = config.plugins) !== null && _a !== void 0 ? _a : []; | ||
@@ -15,0 +16,0 @@ } |
@@ -31,3 +31,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
if (onDidChangeWatchedFilesCb.has(cb)) { | ||
yield cb(params, 'lsp'); | ||
yield cb(params); | ||
} | ||
@@ -34,0 +34,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import * as shared from '@volar/shared'; | ||
import * as embeddedLS from '@volar/language-service'; | ||
@@ -37,4 +36,4 @@ import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
}) => void; | ||
pathDelete: (rootUri: shared._2.URI, path: string) => boolean; | ||
pathGet: (rootUri: shared._2.URI, path: string) => { | ||
pathDelete: (path: string) => boolean; | ||
pathGet: (path: string) => { | ||
version: number; | ||
@@ -45,3 +44,3 @@ fileName: string; | ||
} | undefined; | ||
pathHas: (rootUri: shared._2.URI, path: string) => { | ||
pathHas: (path: string) => { | ||
version: number; | ||
@@ -52,3 +51,3 @@ fileName: string; | ||
} | undefined; | ||
pathSet: (rootUri: shared._2.URI, path: string, item: { | ||
pathSet: (path: string, item: { | ||
version: number; | ||
@@ -55,0 +54,0 @@ fileName: string; |
@@ -141,3 +141,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
// web | ||
return shared.getPathOfUri(serverOptions.typescript.tsdk + '/' + ts.getDefaultLibFileName(options)); | ||
return serverOptions.typescript.tsdk + '/' + ts.getDefaultLibFileName(options); | ||
} | ||
@@ -168,14 +168,14 @@ }, | ||
var _a, _b; | ||
const doc = documents.data.pathGet(rootUri, fileName); | ||
const doc = documents.data.pathGet(fileName); | ||
if (doc) { | ||
return doc.version.toString(); | ||
} | ||
return (_b = (_a = scripts.pathGet(rootUri, fileName)) === null || _a === void 0 ? void 0 : _a.version.toString()) !== null && _b !== void 0 ? _b : ''; | ||
return (_b = (_a = scripts.pathGet(fileName)) === null || _a === void 0 ? void 0 : _a.version.toString()) !== null && _b !== void 0 ? _b : ''; | ||
} | ||
function getScriptSnapshot(fileName) { | ||
const doc = documents.data.pathGet(rootUri, fileName); | ||
const doc = documents.data.pathGet(fileName); | ||
if (doc) { | ||
return doc.getSnapshot(); | ||
} | ||
const script = scripts.pathGet(rootUri, fileName); | ||
const script = scripts.pathGet(fileName); | ||
if (script && script.snapshotVersion === script.version) { | ||
@@ -193,3 +193,3 @@ return script.snapshot; | ||
else { | ||
scripts.pathSet(rootUri, fileName, { | ||
scripts.pathSet(fileName, { | ||
version: -1, | ||
@@ -196,0 +196,0 @@ fileName: fileName, |
import { TextDocument } from 'vscode-languageserver-textdocument'; | ||
import * as vscode from 'vscode-languageserver'; | ||
import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
import type * as _ from 'vscode-uri'; | ||
interface IncrementalScriptSnapshotChange { | ||
@@ -36,6 +35,6 @@ applied: boolean; | ||
uriSet: (_uri: string, item: IncrementalScriptSnapshot) => void; | ||
pathDelete: (rootUri: _.URI, path: string) => boolean; | ||
pathGet: (rootUri: _.URI, path: string) => IncrementalScriptSnapshot | undefined; | ||
pathHas: (rootUri: _.URI, path: string) => IncrementalScriptSnapshot | undefined; | ||
pathSet: (rootUri: _.URI, path: string, item: IncrementalScriptSnapshot) => void; | ||
pathDelete: (path: string) => boolean; | ||
pathGet: (path: string) => IncrementalScriptSnapshot | undefined; | ||
pathHas: (path: string) => IncrementalScriptSnapshot | undefined; | ||
pathSet: (path: string, item: IncrementalScriptSnapshot) => void; | ||
}; | ||
@@ -42,0 +41,0 @@ onDidChangeContent: (cb: (params: vscode.DidChangeTextDocumentParams) => void) => () => boolean; |
@@ -1,2 +0,1 @@ | ||
import { URI } from 'vscode-uri'; | ||
export * as _ from 'vscode-uri'; | ||
@@ -18,6 +17,6 @@ interface Options<T> { | ||
uriSet: (_uri: string, item: T) => void; | ||
pathDelete: (rootUri: URI, path: string) => boolean; | ||
pathGet: (rootUri: URI, path: string) => T | undefined; | ||
pathHas: (rootUri: URI, path: string) => T | undefined; | ||
pathSet: (rootUri: URI, path: string, item: T) => void; | ||
pathDelete: (path: string) => boolean; | ||
pathGet: (path: string) => T | undefined; | ||
pathHas: (path: string) => T | undefined; | ||
pathSet: (path: string, item: T) => void; | ||
}; |
@@ -7,4 +7,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function createUriMap(map = new Map()) { | ||
const uriToUriKeys = new Map(); | ||
const pathToUriKeys = new WeakMap(); | ||
const uriToUri = new Map(); | ||
const pathToUri = new Map(); | ||
return { | ||
@@ -23,16 +23,11 @@ clear, | ||
function getUriByUri(uri) { | ||
if (!uriToUriKeys.has(uri)) | ||
uriToUriKeys.set(uri, normalizeUri(uri).toLowerCase()); | ||
return uriToUriKeys.get(uri); | ||
if (!uriToUri.has(uri)) | ||
uriToUri.set(uri, normalizeUri(uri).toLowerCase()); | ||
return uriToUri.get(uri); | ||
} | ||
function getUriByPath(rootUri, path) { | ||
let map = pathToUriKeys.get(rootUri); | ||
if (!map) { | ||
map = new Map(); | ||
pathToUriKeys.set(rootUri, map); | ||
function getUriByPath(path) { | ||
if (!pathToUri.has(path)) { | ||
pathToUri.set(path, shared.getUriByPath(path).toLowerCase()); | ||
} | ||
if (!map.has(path)) { | ||
map.set(path, shared.getUriByPath(path).toLowerCase()); | ||
} | ||
return map.get(path); | ||
return pathToUri.get(path); | ||
} | ||
@@ -57,13 +52,13 @@ function clear() { | ||
} | ||
function pathDelete(rootUri, path) { | ||
return uriDelete(getUriByPath(rootUri, path)); | ||
function pathDelete(path) { | ||
return uriDelete(getUriByPath(path)); | ||
} | ||
function pathGet(rootUri, path) { | ||
return uriGet(getUriByPath(rootUri, path)); | ||
function pathGet(path) { | ||
return uriGet(getUriByPath(path)); | ||
} | ||
function pathHas(rootUri, path) { | ||
return uriGet(getUriByPath(rootUri, path)); | ||
function pathHas(path) { | ||
return uriGet(getUriByPath(path)); | ||
} | ||
function pathSet(rootUri, path, item) { | ||
return uriSet(getUriByPath(rootUri, path), item); | ||
function pathSet(path, item) { | ||
return uriSet(getUriByPath(path), item); | ||
} | ||
@@ -70,0 +65,0 @@ } |
@@ -15,2 +15,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const vscode = require("vscode-languageserver"); | ||
const vscode_uri_1 = require("vscode-uri"); | ||
const protocol_1 = require("../protocol"); | ||
@@ -30,6 +31,6 @@ const utilities_1 = require("./ts/utilities"); | ||
}; | ||
const pendings = new Set(); | ||
const pendings = []; | ||
const changes = []; | ||
const onReadys = []; | ||
let checking = false; | ||
let loading = false; | ||
let connection; | ||
@@ -55,3 +56,3 @@ return { | ||
} | ||
fireChanges(params, 'lsp'); | ||
fireChanges(params); | ||
}); | ||
@@ -111,6 +112,6 @@ for (const cb of onReadys) { | ||
if (connection) { | ||
addPending(statAsync(connection, fsPath, dir)); | ||
addPending('Stat', fsPath, statAsync(connection, fsPath, dir)); | ||
} | ||
else { | ||
onReadys.push((connection) => addPending(statAsync(connection, fsPath, dir))); | ||
onReadys.push((connection) => addPending('Stat', fsPath, statAsync(connection, fsPath, dir))); | ||
} | ||
@@ -128,6 +129,6 @@ return false; | ||
if (connection) { | ||
addPending(readFileAsync(connection, fsPath, dir)); | ||
addPending('Read File', fsPath, readFileAsync(connection, fsPath, dir)); | ||
} | ||
else { | ||
onReadys.push((connection) => addPending(readFileAsync(connection, fsPath, dir))); | ||
onReadys.push((connection) => addPending('Read File', fsPath, readFileAsync(connection, fsPath, dir))); | ||
} | ||
@@ -146,6 +147,6 @@ return ''; | ||
if (connection) { | ||
addPending(readDirectoryAsync(connection, dirPath, dir)); | ||
addPending('Read Directory', dirPath, readDirectoryAsync(connection, dirPath, dir)); | ||
} | ||
else { | ||
onReadys.push((connection) => addPending(readDirectoryAsync(connection, dirPath, dir))); | ||
onReadys.push((connection) => addPending('Read Directory', dirPath, readDirectoryAsync(connection, dirPath, dir))); | ||
} | ||
@@ -167,6 +168,6 @@ } | ||
if (connection) { | ||
addPending(readDirectoryAsync(connection, fsPath, dir)); | ||
addPending('Read Directory', fsPath, readDirectoryAsync(connection, fsPath, dir)); | ||
} | ||
else { | ||
onReadys.push((connection) => addPending(readDirectoryAsync(connection, fsPath, dir))); | ||
onReadys.push((connection) => addPending('Read Directory', fsPath, readDirectoryAsync(connection, fsPath, dir))); | ||
} | ||
@@ -179,11 +180,25 @@ } | ||
const uri = shared.getUriByPath(fsPath); | ||
const result = yield connection.sendRequest(protocol_1.FsStatRequest.type, uri); | ||
if ((result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.File || (result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.SymbolicLink) { | ||
const name = path.basename(fsPath); | ||
dir.fileTypes.set(name, result.type); | ||
changes.push({ | ||
uri: uri, | ||
type: vscode.FileChangeType.Created, | ||
}); | ||
if (uri.startsWith('https://cdn.jsdelivr.net/npm/')) { // stat request always response file type for jsdelivr | ||
const text = yield readJsdelivrFile(connection, uri); | ||
if (text !== undefined) { | ||
const name = path.basename(fsPath); | ||
dir.fileTypes.set(name, vscode_html_languageservice_1.FileType.File); | ||
dir.fileTexts.set(name, text); | ||
changes.push({ | ||
uri: uri, | ||
type: vscode.FileChangeType.Created, | ||
}); | ||
} | ||
} | ||
else { | ||
const result = yield connection.sendRequest(protocol_1.FsStatRequest.type, uri); | ||
if ((result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.File || (result === null || result === void 0 ? void 0 : result.type) === vscode_html_languageservice_1.FileType.SymbolicLink) { | ||
const name = path.basename(fsPath); | ||
dir.fileTypes.set(name, result.type); | ||
changes.push({ | ||
uri: uri, | ||
type: vscode.FileChangeType.Created, | ||
}); | ||
} | ||
} | ||
}); | ||
@@ -194,13 +209,40 @@ } | ||
const uri = shared.getUriByPath(fsPath); | ||
const text = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri); | ||
if (text) { | ||
const name = path.basename(fsPath); | ||
dir.fileTexts.set(name, text); | ||
changes.push({ | ||
uri: uri, | ||
type: vscode.FileChangeType.Changed, | ||
}); | ||
if (uri.startsWith('https://cdn.jsdelivr.net/npm/')) { | ||
const text = yield readJsdelivrFile(connection, uri); | ||
if (text !== undefined) { | ||
const name = path.basename(fsPath); | ||
dir.fileTexts.set(name, text); | ||
changes.push({ | ||
uri: uri, | ||
type: vscode.FileChangeType.Changed, | ||
}); | ||
} | ||
} | ||
else { | ||
const text = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri); | ||
if (text) { | ||
const name = path.basename(fsPath); | ||
dir.fileTexts.set(name, text); | ||
changes.push({ | ||
uri: uri, | ||
type: vscode.FileChangeType.Changed, | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
function readJsdelivrFile(connection, uri) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// ignore .js because it's no help for intellisense | ||
if (uri.endsWith('.d.ts') || uri.endsWith('.json')) { | ||
const text = (_a = yield connection.sendRequest(protocol_1.FsReadFileRequest.type, uri)) !== null && _a !== void 0 ? _a : undefined; | ||
if (text !== undefined | ||
// ignore https://cdn.jsdelivr.net/npm/@vue/runtime-dom | ||
&& text.indexOf('Minified by jsDelivr') === -1) { | ||
return text; | ||
} | ||
} | ||
}); | ||
} | ||
function readDirectoryAsync(connection, fsPath, dir) { | ||
@@ -222,25 +264,30 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
function addPending(p) { | ||
function addPending(action, fileName, p) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
pendings.add(p); | ||
if (checking === false) { | ||
checking = true; | ||
while (pendings.size > 0) { | ||
const _pendings = [...pendings]; | ||
pendings.clear(); | ||
yield Promise.all(_pendings); | ||
pendings.push([action, fileName, p]); | ||
if (loading === false) { | ||
loading = true; | ||
const progress = yield (connection === null || connection === void 0 ? void 0 : connection.window.createWorkDoneProgress()); | ||
progress === null || progress === void 0 ? void 0 : progress.begin(action); | ||
let i = 0; | ||
while (pendings.length) { | ||
const current = pendings.shift(); | ||
progress === null || progress === void 0 ? void 0 : progress.report(i / pendings.length, vscode_uri_1.URI.parse(shared.getUriByPath(current[1])).fsPath); | ||
yield current; | ||
i++; | ||
} | ||
progress === null || progress === void 0 ? void 0 : progress.done(); | ||
if (changes.length) { | ||
fireChanges({ changes: [...changes] }, 'web-cache-updated'); | ||
fireChanges({ changes: [...changes] }); | ||
changes.length = 0; | ||
} | ||
checking = false; | ||
loading = false; | ||
} | ||
}); | ||
} | ||
function fireChanges(params, reason) { | ||
function fireChanges(params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (const cb of [...onDidChangeWatchedFilesCb]) { | ||
if (onDidChangeWatchedFilesCb.has(cb)) { | ||
yield cb(params, reason); | ||
yield cb(params); | ||
} | ||
@@ -247,0 +294,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import * as shared from '@volar/shared'; | ||
import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
@@ -20,6 +19,6 @@ import * as path from 'typesafe-path'; | ||
uriSet: (_uri: string, item: Project) => void; | ||
pathDelete: (rootUri: shared._2.URI, path: string) => boolean; | ||
pathGet: (rootUri: shared._2.URI, path: string) => Project | undefined; | ||
pathHas: (rootUri: shared._2.URI, path: string) => Project | undefined; | ||
pathSet: (rootUri: shared._2.URI, path: string, item: Project) => void; | ||
pathDelete: (path: string) => boolean; | ||
pathGet: (path: string) => Project | undefined; | ||
pathHas: (path: string) => Project | undefined; | ||
pathSet: (path: string, item: Project) => void; | ||
}; | ||
@@ -53,4 +52,4 @@ documentRegistry: ts.DocumentRegistry; | ||
}) => void; | ||
pathDelete: (rootUri: shared._2.URI, path: string) => boolean; | ||
pathGet: (rootUri: shared._2.URI, path: string) => { | ||
pathDelete: (path: string) => boolean; | ||
pathGet: (path: string) => { | ||
version: number; | ||
@@ -61,3 +60,3 @@ fileName: string; | ||
} | undefined; | ||
pathHas: (rootUri: shared._2.URI, path: string) => { | ||
pathHas: (path: string) => { | ||
version: number; | ||
@@ -68,3 +67,3 @@ fileName: string; | ||
} | undefined; | ||
pathSet: (rootUri: shared._2.URI, path: string, item: { | ||
pathSet: (path: string, item: { | ||
version: number; | ||
@@ -167,2 +166,2 @@ fileName: string; | ||
}>; | ||
export declare function sortTsConfigs(fsPath: path.OsPath, a: path.OsPath, b: path.OsPath): number; | ||
export declare function sortTsConfigs(file: path.PosixPath, a: path.PosixPath, b: path.PosixPath): number; |
@@ -24,6 +24,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const sys = fsHost.getWorkspaceFileSystem(rootUri); | ||
const documentRegistry = ts.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.normalizeFileName(rootUri.fsPath)); | ||
const documentRegistry = ts.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.getPathOfUri(rootUri.toString())); | ||
const projects = (0, uriMap_1.createUriMap)(); | ||
const rootTsConfigs = new Set(sys.readDirectory(rootUri.fsPath, exports.rootTsConfigNames, undefined, ['**/*'])); | ||
const disposeWatch = fsHost.onDidChangeWatchedFiles((params, reason) => __awaiter(this, void 0, void 0, function* () { | ||
const rootTsConfigs = new Set(sys.readDirectory(shared.getPathOfUri(rootUri.toString()), exports.rootTsConfigNames, undefined, ['**/*']).map(fileName => shared.normalizeFileName(fileName))); | ||
const disposeWatch = fsHost.onDidChangeWatchedFiles((params) => __awaiter(this, void 0, void 0, function* () { | ||
const disposes = []; | ||
@@ -33,4 +33,4 @@ for (const change of params.changes) { | ||
if (change.type === vscode.FileChangeType.Created) { | ||
if (shared.isFileInDir(vscode_uri_1.URI.parse(change.uri).fsPath, rootUri.fsPath)) { | ||
rootTsConfigs.add(vscode_uri_1.URI.parse(change.uri).fsPath); | ||
if (shared.isFileInDir(shared.getPathOfUri(change.uri), shared.getPathOfUri(rootUri.toString()))) { | ||
rootTsConfigs.add(shared.getPathOfUri(change.uri)); | ||
} | ||
@@ -40,3 +40,3 @@ } | ||
if (change.type === vscode.FileChangeType.Deleted) { | ||
rootTsConfigs.delete(vscode_uri_1.URI.parse(change.uri).fsPath); | ||
rootTsConfigs.delete(shared.getPathOfUri(change.uri)); | ||
} | ||
@@ -52,5 +52,2 @@ const _project = projects.uriGet(change.uri); | ||
} | ||
if (reason === 'web-cache-updated' && params.changes.some(change => change.uri.indexOf('/node_modules/') >= 0)) { | ||
clearProjects(); | ||
} | ||
return Promise.all(disposes); | ||
@@ -112,7 +109,7 @@ })); | ||
for (const rootTsConfig of rootTsConfigs) { | ||
if (shared.isFileInDir(uri.fsPath, path.dirname(rootTsConfig))) { | ||
if (shared.isFileInDir(shared.getPathOfUri(uri.toString()), path.dirname(rootTsConfig))) { | ||
matches.push(rootTsConfig); | ||
} | ||
} | ||
matches = matches.sort((a, b) => sortTsConfigs(uri.fsPath, a, b)); | ||
matches = matches.sort((a, b) => sortTsConfigs(shared.getPathOfUri(uri.toString()), a, b)); | ||
if (matches.length) { | ||
@@ -125,6 +122,8 @@ yield getParsedCommandLine(matches[0]); | ||
return findTsconfig((tsconfig) => __awaiter(this, void 0, void 0, function* () { | ||
const map = (0, uriMap_1.createUriMap)(); | ||
const parsedCommandLine = yield getParsedCommandLine(tsconfig); | ||
// use toLowerCase to fix https://github.com/johnsoncodehk/volar/issues/1125 | ||
const fileNames = new Set(parsedCommandLine.fileNames.map(fileName => shared.normalizeFileName(fileName.toLowerCase()))); | ||
return fileNames.has(shared.normalizeFileName(uri.fsPath.toLowerCase())); | ||
for (const fileName of parsedCommandLine.fileNames) { | ||
map.pathSet(fileName, true); | ||
} | ||
return map.uriHas(uri.toString()); | ||
})); | ||
@@ -135,3 +134,3 @@ } | ||
var _a; | ||
const project = yield projects.pathGet(rootUri, tsconfig); | ||
const project = yield projects.pathGet(tsconfig); | ||
const ls = project === null || project === void 0 ? void 0 : project.getLanguageServiceDontCreate(); | ||
@@ -145,4 +144,4 @@ const validDoc = (_a = ls === null || ls === void 0 ? void 0 : ls.context.typescriptLanguageService.getProgram()) === null || _a === void 0 ? void 0 : _a.getSourceFile(shared.getPathOfUri(uri.toString())); | ||
const checked = new Set(); | ||
for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(uri.fsPath, a, b))) { | ||
const project = yield projects.pathGet(rootUri, rootTsConfig); | ||
for (const rootTsConfig of [...rootTsConfigs].sort((a, b) => sortTsConfigs(shared.getPathOfUri(uri.toString()), a, b))) { | ||
const project = yield projects.pathGet(rootTsConfig); | ||
if (project) { | ||
@@ -214,6 +213,6 @@ let chains = yield getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []); | ||
const tsConfig = shared.normalizeFileName(_tsConfig); | ||
let project = projects.pathGet(rootUri, tsConfig); | ||
let project = projects.pathGet(tsConfig); | ||
if (!project) { | ||
project = (0, project_1.createProject)(runtimeEnv, plugins, fsHost, ts, vscode_uri_1.URI.parse(shared.getUriByPath(path.dirname(tsConfig))), tsConfig, tsLocalized, documents, configHost, documentRegistry, cancelTokenHost, serverOptions); | ||
projects.pathSet(rootUri, tsConfig, project); | ||
projects.pathSet(tsConfig, project); | ||
} | ||
@@ -225,5 +224,5 @@ return project; | ||
exports.createWorkspaceProjects = createWorkspaceProjects; | ||
function sortTsConfigs(fsPath, a, b) { | ||
const inA = shared.isFileInDir(fsPath, path.dirname(a)); | ||
const inB = shared.isFileInDir(fsPath, path.dirname(b)); | ||
function sortTsConfigs(file, a, b) { | ||
const inA = shared.isFileInDir(file, path.dirname(a)); | ||
const inB = shared.isFileInDir(file, path.dirname(b)); | ||
if (inA !== inB) { | ||
@@ -234,4 +233,4 @@ const aWeight = inA ? 1 : 0; | ||
} | ||
const aLength = shared.normalizeFileName(a).split('/').length; | ||
const bLength = shared.normalizeFileName(b).split('/').length; | ||
const aLength = a.split('/').length; | ||
const bLength = b.split('/').length; | ||
if (aLength === bLength) { | ||
@@ -238,0 +237,0 @@ const aWeight = path.basename(a) === 'tsconfig.json' ? 1 : 0; |
@@ -1,2 +0,1 @@ | ||
import * as shared from '@volar/shared'; | ||
import { ConfigurationHost } from '@volar/language-service'; | ||
@@ -8,3 +7,2 @@ import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
import { createSnapshots } from './snapshots'; | ||
import * as path from 'typesafe-path'; | ||
import { CancellationTokenHost } from './cancellationPipe'; | ||
@@ -22,6 +20,6 @@ export interface Workspaces extends ReturnType<typeof createWorkspaces> { | ||
uriSet: (_uri: string, item: import("./project").Project) => void; | ||
pathDelete: (rootUri: shared._2.URI, path: string) => boolean; | ||
pathGet: (rootUri: shared._2.URI, path: string) => import("./project").Project | undefined; | ||
pathHas: (rootUri: shared._2.URI, path: string) => import("./project").Project | undefined; | ||
pathSet: (rootUri: shared._2.URI, path: string, item: import("./project").Project) => void; | ||
pathDelete: (path: string) => boolean; | ||
pathGet: (path: string) => import("./project").Project | undefined; | ||
pathHas: (path: string) => import("./project").Project | undefined; | ||
pathSet: (path: string, item: import("./project").Project) => void; | ||
}; | ||
@@ -32,3 +30,3 @@ documentRegistry: ts.DocumentRegistry; | ||
project: { | ||
tsConfig: path.PosixPath | ts.CompilerOptions; | ||
tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions; | ||
scripts: { | ||
@@ -56,4 +54,4 @@ clear: () => void; | ||
}) => void; | ||
pathDelete: (rootUri: shared._2.URI, path: string) => boolean; | ||
pathGet: (rootUri: shared._2.URI, path: string) => { | ||
pathDelete: (path: string) => boolean; | ||
pathGet: (path: string) => { | ||
version: number; | ||
@@ -64,3 +62,3 @@ fileName: string; | ||
} | undefined; | ||
pathHas: (rootUri: shared._2.URI, path: string) => { | ||
pathHas: (path: string) => { | ||
version: number; | ||
@@ -71,3 +69,3 @@ fileName: string; | ||
} | undefined; | ||
pathSet: (rootUri: shared._2.URI, path: string, item: { | ||
pathSet: (path: string, item: { | ||
version: number; | ||
@@ -173,3 +171,3 @@ fileName: string; | ||
project: { | ||
tsConfig: path.PosixPath | ts.CompilerOptions; | ||
tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions; | ||
scripts: { | ||
@@ -197,4 +195,4 @@ clear: () => void; | ||
}) => void; | ||
pathDelete: (rootUri: shared._2.URI, path: string) => boolean; | ||
pathGet: (rootUri: shared._2.URI, path: string) => { | ||
pathDelete: (path: string) => boolean; | ||
pathGet: (path: string) => { | ||
version: number; | ||
@@ -205,3 +203,3 @@ fileName: string; | ||
} | undefined; | ||
pathHas: (rootUri: shared._2.URI, path: string) => { | ||
pathHas: (path: string) => { | ||
version: number; | ||
@@ -212,3 +210,3 @@ fileName: string; | ||
} | undefined; | ||
pathSet: (rootUri: shared._2.URI, path: string, item: { | ||
pathSet: (path: string, item: { | ||
version: number; | ||
@@ -308,3 +306,3 @@ fileName: string; | ||
project: { | ||
tsConfig: path.PosixPath | ts.CompilerOptions; | ||
tsConfig: import("typesafe-path").PosixPath | ts.CompilerOptions; | ||
scripts: { | ||
@@ -332,4 +330,4 @@ clear: () => void; | ||
}) => void; | ||
pathDelete: (rootUri: shared._2.URI, path: string) => boolean; | ||
pathGet: (rootUri: shared._2.URI, path: string) => { | ||
pathDelete: (path: string) => boolean; | ||
pathGet: (path: string) => { | ||
version: number; | ||
@@ -340,3 +338,3 @@ fileName: string; | ||
} | undefined; | ||
pathHas: (rootUri: shared._2.URI, path: string) => { | ||
pathHas: (path: string) => { | ||
version: number; | ||
@@ -347,3 +345,3 @@ fileName: string; | ||
} | undefined; | ||
pathSet: (rootUri: shared._2.URI, path: string, item: { | ||
pathSet: (path: string, item: { | ||
version: number; | ||
@@ -350,0 +348,0 @@ fileName: string; |
@@ -14,3 +14,2 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const vscode = require("vscode-languageserver"); | ||
const vscode_uri_1 = require("vscode-uri"); | ||
const types_1 = require("../types"); | ||
@@ -145,5 +144,4 @@ const workspaceProjects_1 = require("./workspaceProjects"); | ||
const rootUris = [...workspaces.keys()] | ||
.filter(rootUri => vscode_uri_1.URI.parse(rootUri).scheme === vscode_uri_1.URI.parse(uri).scheme) // fix https://github.com/johnsoncodehk/volar/issues/1946#issuecomment-1272430742 | ||
.filter(rootUri => shared.isFileInDir(vscode_uri_1.URI.parse(uri).fsPath, vscode_uri_1.URI.parse(rootUri).fsPath)) | ||
.sort((a, b) => (0, workspaceProjects_1.sortTsConfigs)(vscode_uri_1.URI.parse(uri).fsPath, vscode_uri_1.URI.parse(a).fsPath, vscode_uri_1.URI.parse(b).fsPath)); | ||
.filter(rootUri => shared.isFileInDir(shared.getPathOfUri(uri), shared.getPathOfUri(rootUri))) | ||
.sort((a, b) => (0, workspaceProjects_1.sortTsConfigs)(shared.getPathOfUri(uri), shared.getPathOfUri(a), shared.getPathOfUri(b))); | ||
for (const rootUri of rootUris) { | ||
@@ -150,0 +148,0 @@ const workspace = yield workspaces.get(rootUri); |
{ | ||
"name": "@volar/language-server", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"main": "out/index.js", | ||
@@ -20,5 +20,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"@volar/language-core": "1.0.12", | ||
"@volar/language-service": "1.0.12", | ||
"@volar/shared": "1.0.12", | ||
"@volar/language-core": "1.0.13", | ||
"@volar/language-service": "1.0.13", | ||
"@volar/shared": "1.0.13", | ||
"request-light": "^0.6.0", | ||
@@ -32,3 +32,3 @@ "typesafe-path": "^0.2.2", | ||
}, | ||
"gitHead": "2426aa8ec6731a6f6d88086da7021a32d9306de3" | ||
"gitHead": "cba2eba187b2d82e1d45dd86b3edeab0ca7caad6" | ||
} |
274350
5300
+ Added@volar/language-core@1.0.13(transitive)
+ Added@volar/language-service@1.0.13(transitive)
+ Added@volar/shared@1.0.13(transitive)
+ Added@volar/source-map@1.0.13(transitive)
+ Added@volar/transforms@1.0.13(transitive)
+ Added@volar/typescript-faster@1.0.13(transitive)
- Removed@volar/language-core@1.0.12(transitive)
- Removed@volar/language-service@1.0.12(transitive)
- Removed@volar/shared@1.0.12(transitive)
- Removed@volar/source-map@1.0.12(transitive)
- Removed@volar/transforms@1.0.12(transitive)
- Removed@volar/typescript-faster@1.0.12(transitive)
Updated@volar/language-core@1.0.13
Updated@volar/shared@1.0.13