@volar/language-server 1.0.18 → 1.0.20

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.
@@ -18,22 +18,20 @@ const inferredCompilerOptions_1 = require("./utils/inferredCompilerOptions");
18
18
  const serverConfig_1 = require("./utils/serverConfig");
19
19
  const uriMap_1 = require("./utils/uriMap");
20
20
  exports.rootTsConfigNames = ['tsconfig.json', 'jsconfig.json'];
21
- function createWorkspace(params) {
21
+ function createWorkspace(context) {
22
+ var _a, _b, _c;
22
23
  return __awaiter(this, void 0, void 0, function* () {
23
- const { rootUri } = params;
24
- const { ts, fileSystemHost, initOptions, configurationHost } = params.workspaces;
25
24
  let inferredProject;
26
- const workspacePlugins = (0, serverConfig_1.loadCustomPlugins)(shared.getPathOfUri(rootUri.toString()), initOptions.configFilePath);
27
- const sys = fileSystemHost.getWorkspaceFileSystem(rootUri);
28
- const documentRegistry = ts.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.getPathOfUri(rootUri.toString()));
25
+ const serverConfig = (0, serverConfig_1.loadServerConfig)(shared.getPathOfUri(context.rootUri.toString()), context.workspaces.initOptions.configFilePath);
26
+ const sys = (_a = context.workspaces.fileSystemHost) === null || _a === void 0 ? void 0 : _a.getWorkspaceFileSystem(context.rootUri);
27
+ const documentRegistry = sys ? (_b = context.workspaces.ts) === null || _b === void 0 ? void 0 : _b.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.getPathOfUri(context.rootUri.toString())) : undefined;
29
28
  const projects = (0, uriMap_1.createUriMap)();
30
- const rootTsConfigs = new Set(sys.readDirectory(shared.getPathOfUri(rootUri.toString()), exports.rootTsConfigNames, undefined, ['**/*']).map(fileName => shared.normalizeFileName(fileName)));
31
- const disposeWatch = fileSystemHost.onDidChangeWatchedFiles((params) => __awaiter(this, void 0, void 0, function* () {
32
- const disposes = [];
33
- for (const change of params.changes) {
29
+ const rootTsConfigs = new Set(sys === null || sys === void 0 ? void 0 : sys.readDirectory(shared.getPathOfUri(context.rootUri.toString()), exports.rootTsConfigNames, undefined, ['**/*']).map(fileName => shared.normalizeFileName(fileName)));
30
+ const disposeTsConfigWatch = (_c = context.workspaces.fileSystemHost) === null || _c === void 0 ? void 0 : _c.onDidChangeWatchedFiles(({ changes }) => {
31
+ for (const change of changes) {
34
32
  if (exports.rootTsConfigNames.includes(change.uri.substring(change.uri.lastIndexOf('/') + 1))) {
35
33
  if (change.type === vscode.FileChangeType.Created) {
36
- if (shared.isFileInDir(shared.getPathOfUri(change.uri), shared.getPathOfUri(rootUri.toString()))) {
34
+ if (shared.isFileInDir(shared.getPathOfUri(change.uri), shared.getPathOfUri(context.rootUri.toString()))) {
37
35
  rootTsConfigs.add(shared.getPathOfUri(change.uri));
38
36
  }
39
37
  }
@@ -41,17 +39,13 @@ function createWorkspace(params) {
41
39
  if (change.type === vscode.FileChangeType.Deleted) {
42
40
  rootTsConfigs.delete(shared.getPathOfUri(change.uri));
43
41
  }
44
- const _project = projects.uriGet(change.uri);
42
+ const project = projects.uriGet(change.uri);
45
43
  projects.uriDelete(change.uri);
46
- disposes.push((() => __awaiter(this, void 0, void 0, function* () {
47
- var _a;
48
- (_a = (yield _project)) === null || _a === void 0 ? void 0 : _a.dispose();
49
- }))());
44
+ project === null || project === void 0 ? void 0 : project.then(project => project.dispose());
50
45
  }
51
46
  }
52
47
  }
53
- return Promise.all(disposes);
54
- }));
48
+ });
55
49
  return {
56
50
  projects,
57
51
  documentRegistry,
@@ -61,7 +55,7 @@ function createWorkspace(params) {
61
55
  reload: clearProjects,
62
56
  dispose() {
63
57
  clearProjects();
64
- disposeWatch();
58
+ disposeTsConfigWatch === null || disposeTsConfigWatch === void 0 ? void 0 : disposeTsConfigWatch();
65
59
  },
66
60
  };
67
61
  function clearProjects() {
@@ -91,13 +85,13 @@ function createWorkspace(params) {
91
85
  function getInferredProject() {
92
86
  if (!inferredProject) {
93
87
  inferredProject = (() => __awaiter(this, void 0, void 0, function* () {
94
- const inferOptions = yield (0, inferredCompilerOptions_1.getInferredCompilerOptions)(ts, configurationHost);
88
+ const inferOptions = yield (0, inferredCompilerOptions_1.getInferredCompilerOptions)(context.workspaces.configurationHost);
95
89
  return (0, project_1.createProject)({
96
- workspace: params,
97
- workspacePlugins,
98
- rootUri,
90
+ workspace: context,
91
+ rootUri: context.rootUri,
99
92
  tsConfig: inferOptions,
100
93
  documentRegistry,
94
+ serverConfig,
101
95
  });
102
96
  }))();
103
97
  }
@@ -124,9 +118,10 @@ function createWorkspace(params) {
124
118
  }
125
119
  function findDirectIncludeTsconfig() {
126
120
  return findTsconfig((tsconfig) => __awaiter(this, void 0, void 0, function* () {
121
+ var _a;
127
122
  const map = (0, uriMap_1.createUriMap)();
128
123
  const parsedCommandLine = yield getParsedCommandLine(tsconfig);
129
- for (const fileName of parsedCommandLine.fileNames) {
124
+ for (const fileName of (_a = parsedCommandLine === null || parsedCommandLine === void 0 ? void 0 : parsedCommandLine.fileNames) !== null && _a !== void 0 ? _a : []) {
130
125
  map.pathSet(fileName, true);
131
126
  }
132
127
  return map.uriHas(uri.toString());
@@ -134,10 +129,10 @@ function createWorkspace(params) {
134
129
  }
135
130
  function findIndirectReferenceTsconfig() {
136
131
  return findTsconfig((tsconfig) => __awaiter(this, void 0, void 0, function* () {
137
- var _a;
132
+ var _a, _b;
138
133
  const project = yield projects.pathGet(tsconfig);
139
134
  const ls = project === null || project === void 0 ? void 0 : project.getLanguageServiceDontCreate();
140
- 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()));
135
+ const validDoc = (_b = (_a = ls === null || ls === void 0 ? void 0 : ls.context.typescript) === null || _a === void 0 ? void 0 : _a.languageService.getProgram()) === null || _b === void 0 ? void 0 : _b.getSourceFile(shared.getPathOfUri(uri.toString()));
141
136
  return !!validDoc;
142
137
  }));
143
138
  }
@@ -148,7 +143,7 @@ function createWorkspace(params) {
148
143
  const project = yield projects.pathGet(rootTsConfig);
149
144
  if (project) {
150
145
  let chains = yield getReferencesChains(project.getParsedCommandLine(), rootTsConfig, []);
151
- if (initOptions.reverseConfigFilePriority) {
146
+ if (context.workspaces.initOptions.reverseConfigFilePriority) {
152
147
  chains = chains.reverse();
153
148
  }
154
149
  for (const chain of chains) {
@@ -174,7 +169,7 @@ function createWorkspace(params) {
174
169
  for (const projectReference of parsedCommandLine.projectReferences) {
175
170
  let tsConfigPath = projectReference.path;
176
171
  // fix https://github.com/johnsoncodehk/volar/issues/712
177
- if (!sys.fileExists(tsConfigPath)) {
172
+ if (sys && !sys.fileExists(tsConfigPath)) {
178
173
  const newTsConfigPath = path.join(tsConfigPath, 'tsconfig.json');
179
174
  const newJsConfigPath = path.join(tsConfigPath, 'jsconfig.json');
180
175
  if (sys.fileExists(newTsConfigPath)) {
@@ -190,8 +185,10 @@ function createWorkspace(params) {
190
185
  }
191
186
  else {
192
187
  const referenceParsedCommandLine = yield getParsedCommandLine(tsConfigPath);
193
- for (const chain of yield getReferencesChains(referenceParsedCommandLine, tsConfigPath, [...before, tsConfig])) {
194
- newChains.push(chain);
188
+ if (referenceParsedCommandLine) {
189
+ for (const chain of yield getReferencesChains(referenceParsedCommandLine, tsConfigPath, [...before, tsConfig])) {
190
+ newChains.push(chain);
191
+ }
195
192
  }
196
193
  }
197
194
  }
@@ -205,7 +202,7 @@ function createWorkspace(params) {
205
202
  function getParsedCommandLine(tsConfig) {
206
203
  return __awaiter(this, void 0, void 0, function* () {
207
204
  const project = yield getProjectByCreate(tsConfig);
208
- return project.getParsedCommandLine();
205
+ return project === null || project === void 0 ? void 0 : project.getParsedCommandLine();
209
206
  });
210
207
  }
211
208
  });
@@ -213,10 +210,10 @@ function createWorkspace(params) {
213
210
  function getProjectByCreate(_tsConfig) {
214
211
  const tsConfig = shared.normalizeFileName(_tsConfig);
215
212
  let project = projects.pathGet(tsConfig);
216
- if (!project) {
213
+ if (!project && documentRegistry) {
217
214
  project = (0, project_1.createProject)({
218
- workspace: params,
219
- workspacePlugins,
215
+ workspace: context,
216
+ serverConfig,
220
217
  rootUri: vscode_uri_1.URI.parse(shared.getUriByPath(path.dirname(tsConfig))),
221
218
  tsConfig,
222
219
  documentRegistry,