@volar/language-server 1.7.8 → 1.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,5 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
2
  export type CancellationTokenHost = ReturnType<typeof createCancellationTokenHost>;
3
3
  export declare function createCancellationTokenHost(_cancellationPipeName: string | undefined): {
4
- createCancellationToken(original: vscode.CancellationToken): vscode.CancellationToken;
5
- getMtime(): number;
4
+ createCancellationToken(original?: vscode.CancellationToken): vscode.CancellationToken;
6
5
  };
@@ -6,27 +6,30 @@ function createCancellationTokenHost(_cancellationPipeName) {
6
6
  if (_cancellationPipeName === undefined) {
7
7
  return {
8
8
  createCancellationToken(original) {
9
- return original;
9
+ return original ?? vscode.CancellationToken.None;
10
10
  },
11
- getMtime() {
12
- return -1;
13
- }
14
11
  };
15
12
  }
16
13
  const cancellationPipeName = _cancellationPipeName;
17
14
  const fs = require('fs');
18
15
  return {
19
16
  createCancellationToken,
20
- getMtime,
21
17
  };
22
18
  function createCancellationToken(original) {
23
19
  const mtime = getMtime();
20
+ let currentMtime = mtime;
21
+ let updateAt = Date.now();
24
22
  const token = {
25
23
  get isCancellationRequested() {
26
- if (original.isCancellationRequested) {
24
+ if (original?.isCancellationRequested) {
27
25
  return true;
28
26
  }
29
- return getMtime() !== mtime;
27
+ // debounce 20ms
28
+ if (currentMtime === mtime && Date.now() - updateAt >= 20) {
29
+ currentMtime = getMtime();
30
+ updateAt = Date.now();
31
+ }
32
+ return currentMtime !== mtime;
30
33
  },
31
34
  onCancellationRequested: vscode.Event.None,
32
35
  };
@@ -13,7 +13,7 @@ export interface ProjectContext extends WorkspaceContext {
13
13
  export type Project = ReturnType<typeof createProject>;
14
14
  export declare function createProject(context: ProjectContext): Promise<{
15
15
  context: ProjectContext;
16
- tsConfig: ts.CompilerOptions | path.PosixPath;
16
+ tsConfig: path.PosixPath | ts.CompilerOptions;
17
17
  scripts: {
18
18
  clear: () => void;
19
19
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -9,8 +9,14 @@ const uriMap_1 = require("./utils/uriMap");
9
9
  const typescript_1 = require("@volar/typescript");
10
10
  async function createProject(context) {
11
11
  let projectVersion = 0;
12
- let projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
12
+ let token = context.workspaces.cancelTokenHost.createCancellationToken();
13
13
  let languageService;
14
+ const tsToken = {
15
+ isCancellationRequested() {
16
+ return token.isCancellationRequested;
17
+ },
18
+ throwIfCancellationRequested() { },
19
+ };
14
20
  const { uriToFileName, fileNameToUri, fs } = context.server.runtimeEnv;
15
21
  const env = {
16
22
  uriToFileName,
@@ -25,12 +31,6 @@ async function createProject(context) {
25
31
  };
26
32
  const fsScriptsCache = (0, uriMap_1.createUriMap)(fileNameToUri);
27
33
  const askedFiles = (0, uriMap_1.createUriMap)(fileNameToUri);
28
- const token = {
29
- isCancellationRequested() {
30
- return context.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
31
- },
32
- throwIfCancellationRequested() { },
33
- };
34
34
  const languageHost = {
35
35
  getProjectVersion: () => projectVersion,
36
36
  getScriptFileNames: () => parsedCommandLine.fileNames,
@@ -46,7 +46,7 @@ async function createProject(context) {
46
46
  }
47
47
  },
48
48
  getLanguageId: (fileName) => context.workspaces.documents.data.pathGet(fileName)?.languageId,
49
- getCancellationToken: () => token,
49
+ getCancellationToken: () => tsToken,
50
50
  getCompilationSettings: () => parsedCommandLine.options,
51
51
  getLocalizedDiagnosticMessages: context.workspaces.tsLocalized ? () => context.workspaces.tsLocalized : undefined,
52
52
  getCurrentDirectory: () => uriToFileName(context.project.rootUri.toString()),
@@ -54,7 +54,7 @@ async function createProject(context) {
54
54
  };
55
55
  const docChangeWatcher = context.workspaces.documents.onDidChangeContent(() => {
56
56
  projectVersion++;
57
- projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
57
+ token = context.workspaces.cancelTokenHost.createCancellationToken();
58
58
  });
59
59
  const fileWatch = env.onDidChangeWatchedFiles?.(params => {
60
60
  onWorkspaceFilesChanged(params.changes);
@@ -89,7 +89,7 @@ async function createProject(context) {
89
89
  if (!parsedCommandLine.fileNames.includes(fileName)) {
90
90
  parsedCommandLine.fileNames.push(fileName);
91
91
  projectVersion++;
92
- projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
92
+ token = context.workspaces.cancelTokenHost.createCancellationToken();
93
93
  }
94
94
  },
95
95
  askedFiles,
@@ -144,7 +144,7 @@ async function createProject(context) {
144
144
  }
145
145
  }
146
146
  if (oldProjectVersion !== projectVersion) {
147
- projectVersionUpdateTime = context.workspaces.cancelTokenHost.getMtime();
147
+ token = context.workspaces.cancelTokenHost.createCancellationToken();
148
148
  }
149
149
  }
150
150
  function dispose() {
@@ -74,24 +74,22 @@ async function startCommonLanguageServer(connection, _plugins, getRuntimeEnv) {
74
74
  },
75
75
  },
76
76
  };
77
- let services = {};
77
+ let config = {};
78
78
  for (const root of roots) {
79
79
  if (root.scheme === 'file') {
80
- let config = (0, serverConfig_1.loadConfig)(root.path, options.configFilePath) ?? {};
81
- for (const plugin of plugins) {
82
- if (plugin.resolveConfig) {
83
- config = await plugin.resolveConfig(config, undefined);
84
- }
85
- }
86
- if (config.services) {
87
- services = {
88
- ...services,
89
- ...config.services,
90
- };
80
+ const workspaceConfig = (0, serverConfig_1.loadConfig)(root.path, options.configFilePath);
81
+ if (workspaceConfig) {
82
+ config = workspaceConfig;
83
+ break;
91
84
  }
92
85
  }
93
86
  }
94
- (0, registerFeatures_1.setupCapabilities)(result.capabilities, options, plugins, getSemanticTokensLegend(), services);
87
+ for (const plugin of plugins) {
88
+ if (plugin.resolveConfig) {
89
+ config = await plugin.resolveConfig(config, undefined);
90
+ }
91
+ }
92
+ (0, registerFeatures_1.setupCapabilities)(result.capabilities, options, plugins, getSemanticTokensLegend(), config.services ?? {});
95
93
  await createLanguageServiceHost();
96
94
  try {
97
95
  // show version on LSP logs
@@ -14,7 +14,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
14
14
  clear: () => void;
15
15
  values: () => IterableIterator<Promise<{
16
16
  context: import("./project").ProjectContext;
17
- tsConfig: ts.CompilerOptions | path.PosixPath;
17
+ tsConfig: path.PosixPath | ts.CompilerOptions;
18
18
  scripts: {
19
19
  clear: () => void;
20
20
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -153,7 +153,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
153
153
  uriDelete: (_uri: string) => boolean;
154
154
  uriGet: (_uri: string) => Promise<{
155
155
  context: import("./project").ProjectContext;
156
- tsConfig: ts.CompilerOptions | path.PosixPath;
156
+ tsConfig: path.PosixPath | ts.CompilerOptions;
157
157
  scripts: {
158
158
  clear: () => void;
159
159
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -292,7 +292,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
292
292
  uriHas: (_uri: string) => boolean;
293
293
  uriSet: (_uri: string, item: Promise<{
294
294
  context: import("./project").ProjectContext;
295
- tsConfig: ts.CompilerOptions | path.PosixPath;
295
+ tsConfig: path.PosixPath | ts.CompilerOptions;
296
296
  scripts: {
297
297
  clear: () => void;
298
298
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -431,7 +431,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
431
431
  pathDelete: (path: string) => boolean;
432
432
  pathGet: (path: string) => Promise<{
433
433
  context: import("./project").ProjectContext;
434
- tsConfig: ts.CompilerOptions | path.PosixPath;
434
+ tsConfig: path.PosixPath | ts.CompilerOptions;
435
435
  scripts: {
436
436
  clear: () => void;
437
437
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -569,7 +569,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
569
569
  }> | undefined;
570
570
  pathHas: (path: string) => Promise<{
571
571
  context: import("./project").ProjectContext;
572
- tsConfig: ts.CompilerOptions | path.PosixPath;
572
+ tsConfig: path.PosixPath | ts.CompilerOptions;
573
573
  scripts: {
574
574
  clear: () => void;
575
575
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -707,7 +707,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
707
707
  }> | undefined;
708
708
  pathSet: (path: string, item: Promise<{
709
709
  context: import("./project").ProjectContext;
710
- tsConfig: ts.CompilerOptions | path.PosixPath;
710
+ tsConfig: path.PosixPath | ts.CompilerOptions;
711
711
  scripts: {
712
712
  clear: () => void;
713
713
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -848,7 +848,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
848
848
  tsconfig: string;
849
849
  project: {
850
850
  context: import("./project").ProjectContext;
851
- tsConfig: ts.CompilerOptions | path.PosixPath;
851
+ tsConfig: path.PosixPath | ts.CompilerOptions;
852
852
  scripts: {
853
853
  clear: () => void;
854
854
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -987,7 +987,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
987
987
  } | undefined>;
988
988
  getInferredProject: () => Promise<{
989
989
  context: import("./project").ProjectContext;
990
- tsConfig: ts.CompilerOptions | path.PosixPath;
990
+ tsConfig: path.PosixPath | ts.CompilerOptions;
991
991
  scripts: {
992
992
  clear: () => void;
993
993
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -1125,7 +1125,7 @@ export declare function createWorkspace(context: WorkspaceContext): Promise<{
1125
1125
  }>;
1126
1126
  getInferredProjectDontCreate: () => Promise<{
1127
1127
  context: import("./project").ProjectContext;
1128
- tsConfig: ts.CompilerOptions | path.PosixPath;
1128
+ tsConfig: path.PosixPath | ts.CompilerOptions;
1129
1129
  scripts: {
1130
1130
  clear: () => void;
1131
1131
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -25,7 +25,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
25
25
  clear: () => void;
26
26
  values: () => IterableIterator<Promise<{
27
27
  context: import("./project").ProjectContext;
28
- tsConfig: ts.CompilerOptions | import("typesafe-path/posix").PosixPath;
28
+ tsConfig: import("typesafe-path/posix").PosixPath | ts.CompilerOptions;
29
29
  scripts: {
30
30
  clear: () => void;
31
31
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -164,7 +164,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
164
164
  uriDelete: (_uri: string) => boolean;
165
165
  uriGet: (_uri: string) => Promise<{
166
166
  context: import("./project").ProjectContext;
167
- tsConfig: ts.CompilerOptions | import("typesafe-path/posix").PosixPath;
167
+ tsConfig: import("typesafe-path/posix").PosixPath | ts.CompilerOptions;
168
168
  scripts: {
169
169
  clear: () => void;
170
170
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -303,7 +303,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
303
303
  uriHas: (_uri: string) => boolean;
304
304
  uriSet: (_uri: string, item: Promise<{
305
305
  context: import("./project").ProjectContext;
306
- tsConfig: ts.CompilerOptions | import("typesafe-path/posix").PosixPath;
306
+ tsConfig: import("typesafe-path/posix").PosixPath | ts.CompilerOptions;
307
307
  scripts: {
308
308
  clear: () => void;
309
309
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -442,7 +442,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
442
442
  pathDelete: (path: string) => boolean;
443
443
  pathGet: (path: string) => Promise<{
444
444
  context: import("./project").ProjectContext;
445
- tsConfig: ts.CompilerOptions | import("typesafe-path/posix").PosixPath;
445
+ tsConfig: import("typesafe-path/posix").PosixPath | ts.CompilerOptions;
446
446
  scripts: {
447
447
  clear: () => void;
448
448
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -580,7 +580,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
580
580
  }> | undefined;
581
581
  pathHas: (path: string) => Promise<{
582
582
  context: import("./project").ProjectContext;
583
- tsConfig: ts.CompilerOptions | import("typesafe-path/posix").PosixPath;
583
+ tsConfig: import("typesafe-path/posix").PosixPath | ts.CompilerOptions;
584
584
  scripts: {
585
585
  clear: () => void;
586
586
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -718,7 +718,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
718
718
  }> | undefined;
719
719
  pathSet: (path: string, item: Promise<{
720
720
  context: import("./project").ProjectContext;
721
- tsConfig: ts.CompilerOptions | import("typesafe-path/posix").PosixPath;
721
+ tsConfig: import("typesafe-path/posix").PosixPath | ts.CompilerOptions;
722
722
  scripts: {
723
723
  clear: () => void;
724
724
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -859,7 +859,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
859
859
  tsconfig: string;
860
860
  project: {
861
861
  context: import("./project").ProjectContext;
862
- tsConfig: ts.CompilerOptions | import("typesafe-path/posix").PosixPath;
862
+ tsConfig: import("typesafe-path/posix").PosixPath | ts.CompilerOptions;
863
863
  scripts: {
864
864
  clear: () => void;
865
865
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -998,7 +998,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
998
998
  } | undefined>;
999
999
  getInferredProject: () => Promise<{
1000
1000
  context: import("./project").ProjectContext;
1001
- tsConfig: ts.CompilerOptions | import("typesafe-path/posix").PosixPath;
1001
+ tsConfig: import("typesafe-path/posix").PosixPath | ts.CompilerOptions;
1002
1002
  scripts: {
1003
1003
  clear: () => void;
1004
1004
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -1136,7 +1136,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
1136
1136
  }>;
1137
1137
  getInferredProjectDontCreate: () => Promise<{
1138
1138
  context: import("./project").ProjectContext;
1139
- tsConfig: ts.CompilerOptions | import("typesafe-path/posix").PosixPath;
1139
+ tsConfig: import("typesafe-path/posix").PosixPath | ts.CompilerOptions;
1140
1140
  scripts: {
1141
1141
  clear: () => void;
1142
1142
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -1279,7 +1279,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
1279
1279
  tsconfig: string;
1280
1280
  project: {
1281
1281
  context: import("./project").ProjectContext;
1282
- tsConfig: ts.CompilerOptions | import("typesafe-path/posix").PosixPath;
1282
+ tsConfig: import("typesafe-path/posix").PosixPath | ts.CompilerOptions;
1283
1283
  scripts: {
1284
1284
  clear: () => void;
1285
1285
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
@@ -1419,7 +1419,7 @@ export declare function createWorkspaces(context: WorkspacesContext): {
1419
1419
  tsconfig: undefined;
1420
1420
  project: {
1421
1421
  context: import("./project").ProjectContext;
1422
- tsConfig: ts.CompilerOptions | import("typesafe-path/posix").PosixPath;
1422
+ tsConfig: import("typesafe-path/posix").PosixPath | ts.CompilerOptions;
1423
1423
  scripts: {
1424
1424
  clear: () => void;
1425
1425
  values: () => IterableIterator<ts.IScriptSnapshot | undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-server",
3
- "version": "1.7.8",
3
+ "version": "1.7.9",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -15,9 +15,9 @@
15
15
  "directory": "packages/language-server"
16
16
  },
17
17
  "dependencies": {
18
- "@volar/language-core": "1.7.8",
19
- "@volar/language-service": "1.7.8",
20
- "@volar/typescript": "1.7.8",
18
+ "@volar/language-core": "1.7.9",
19
+ "@volar/language-service": "1.7.9",
20
+ "@volar/typescript": "1.7.9",
21
21
  "@vscode/l10n": "^0.0.11",
22
22
  "request-light": "^0.7.0",
23
23
  "typesafe-path": "^0.2.2",
@@ -27,7 +27,7 @@
27
27
  "vscode-uri": "^3.0.7"
28
28
  },
29
29
  "devDependencies": {
30
- "@volar/source-map": "1.7.8"
30
+ "@volar/source-map": "1.7.9"
31
31
  },
32
- "gitHead": "e7c1b16e5c78702de6986eafa17ae96000ffe0cb"
32
+ "gitHead": "c28b1b3fc725f38d335f4341179678c78828528f"
33
33
  }