@volar/language-server 1.0.19 → 1.0.21

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,3 +1,5 @@
1
+ import * as vscode from 'vscode-languageserver/browser';
1
2
  import { LanguageServerPlugin } from '../types';
2
3
  export * from '../index';
3
- export declare function createLanguageServer(plugins: LanguageServerPlugin[]): void;
4
+ export declare function createConnection(): vscode.Connection;
5
+ export declare function startLanguageServer(connection: vscode.Connection, ...plugins: LanguageServerPlugin[]): void;
@@ -22,7 +22,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  });
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.createLanguageServer = void 0;
25
+ exports.startLanguageServer = exports.createConnection = void 0;
26
26
  const request_light_1 = require("request-light");
27
27
  const ts = require("typescript/lib/tsserverlibrary"); // bundle typescript lib in web
28
28
  const vscode = require("vscode-languageserver/browser");
@@ -31,11 +31,15 @@ const http_1 = require("../common/schemaRequestHandlers/http");
31
31
  const fileSystems_1 = require("./fileSystems");
32
32
  const shared = require("@volar/shared");
33
33
  __exportStar(require("../index"), exports);
34
- function createLanguageServer(plugins) {
34
+ function createConnection() {
35
35
  const messageReader = new vscode.BrowserMessageReader(self);
36
36
  const messageWriter = new vscode.BrowserMessageWriter(self);
37
37
  const connection = vscode.createConnection(messageReader, messageWriter);
38
- (0, server_1.createCommonLanguageServer)({
38
+ return connection;
39
+ }
40
+ exports.createConnection = createConnection;
41
+ function startLanguageServer(connection, ...plugins) {
42
+ (0, server_1.startCommonLanguageServer)({
39
43
  plugins,
40
44
  connection,
41
45
  runtimeEnv: {
@@ -64,5 +68,5 @@ function createLanguageServer(plugins) {
64
68
  },
65
69
  });
66
70
  }
67
- exports.createLanguageServer = createLanguageServer;
71
+ exports.startLanguageServer = startLanguageServer;
68
72
  //# sourceMappingURL=index.js.map
@@ -14,11 +14,11 @@ const protocol_1 = require("../../protocol");
14
14
  const language_core_1 = require("@volar/language-core");
15
15
  function register(connection, projects) {
16
16
  connection.onNotification(protocol_1.ReportStats.type, () => __awaiter(this, void 0, void 0, function* () {
17
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
17
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
18
18
  for (const [rootUri, _workspace] of projects.workspaces) {
19
19
  connection.console.log('workspace: ' + rootUri);
20
20
  const workspace = yield _workspace;
21
- connection.console.log('documentRegistry stats: ' + workspace.documentRegistry.reportStats());
21
+ connection.console.log('documentRegistry stats: ' + ((_a = workspace.documentRegistry) === null || _a === void 0 ? void 0 : _a.reportStats()));
22
22
  connection.console.log('');
23
23
  connection.console.log('tsconfig: inferred');
24
24
  const _inferredProject = workspace.getInferredProjectDontCreate();
@@ -30,13 +30,13 @@ function register(connection, projects) {
30
30
  .sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.snapshot) === null || _a === void 0 ? void 0 : _a.getLength()) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()) !== null && _d !== void 0 ? _d : 0); })
31
31
  .slice(0, 10)) {
32
32
  connection.console.log(' - ' + script.fileName);
33
- connection.console.log(` size: ${(_a = script.snapshot) === null || _a === void 0 ? void 0 : _a.getLength()}`);
33
+ connection.console.log(` size: ${(_b = script.snapshot) === null || _b === void 0 ? void 0 : _b.getLength()}`);
34
34
  }
35
35
  connection.console.log('files:');
36
36
  for (const script of inferredProject.scripts.values()) {
37
37
  connection.console.log(' - ' + script.fileName);
38
- connection.console.log(` size: ${(_b = script.snapshot) === null || _b === void 0 ? void 0 : _b.getLength()}`);
39
- connection.console.log(` ref counts: "${(_d = (_c = workspace.documentRegistry).getLanguageServiceRefCounts) === null || _d === void 0 ? void 0 : _d.call(_c, script.fileName, (_f = (_e = inferredProject.languageServiceHost).getScriptKind) === null || _f === void 0 ? void 0 : _f.call(_e, script.fileName))})"`);
38
+ connection.console.log(` size: ${(_c = script.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()}`);
39
+ connection.console.log(` ref counts: "${(_e = (_d = workspace.documentRegistry).getLanguageServiceRefCounts) === null || _e === void 0 ? void 0 : _e.call(_d, script.fileName, (_g = (_f = inferredProject.languageServiceHost).getScriptKind) === null || _g === void 0 ? void 0 : _g.call(_f, script.fileName))})"`);
40
40
  }
41
41
  }
42
42
  else {
@@ -52,13 +52,13 @@ function register(connection, projects) {
52
52
  .sort((a, b) => { var _a, _b, _c, _d; return ((_b = (_a = b.snapshot) === null || _a === void 0 ? void 0 : _a.getLength()) !== null && _b !== void 0 ? _b : 0) - ((_d = (_c = a.snapshot) === null || _c === void 0 ? void 0 : _c.getLength()) !== null && _d !== void 0 ? _d : 0); })
53
53
  .slice(0, 10)) {
54
54
  connection.console.log(' - ' + script.fileName);
55
- connection.console.log(` size: ${(_g = script.snapshot) === null || _g === void 0 ? void 0 : _g.getLength()}`);
55
+ connection.console.log(` size: ${(_h = script.snapshot) === null || _h === void 0 ? void 0 : _h.getLength()}`);
56
56
  }
57
57
  connection.console.log('files:');
58
58
  for (const script of project.scripts.values()) {
59
59
  connection.console.log(' - ' + script.fileName);
60
- connection.console.log(` size: ${(_h = script.snapshot) === null || _h === void 0 ? void 0 : _h.getLength()}`);
61
- connection.console.log(` ref counts: "${(_k = (_j = workspace.documentRegistry).getLanguageServiceRefCounts) === null || _k === void 0 ? void 0 : _k.call(_j, script.fileName, (_m = (_l = project.languageServiceHost).getScriptKind) === null || _m === void 0 ? void 0 : _m.call(_l, script.fileName))})"`);
60
+ connection.console.log(` size: ${(_j = script.snapshot) === null || _j === void 0 ? void 0 : _j.getLength()}`);
61
+ connection.console.log(` ref counts: "${(_l = (_k = workspace.documentRegistry).getLanguageServiceRefCounts) === null || _l === void 0 ? void 0 : _l.call(_k, script.fileName, (_o = (_m = project.languageServiceHost).getScriptKind) === null || _o === void 0 ? void 0 : _o.call(_m, script.fileName))})"`);
62
62
  }
63
63
  }
64
64
  connection.console.log('');
@@ -71,11 +71,11 @@ function register(connection, projects) {
71
71
  }
72
72
  }));
73
73
  connection.onRequest(protocol_1.GetVirtualFileNamesRequest.type, (document) => __awaiter(this, void 0, void 0, function* () {
74
- var _o, _p;
74
+ var _p, _q;
75
75
  const project = yield projects.getProject(document.uri);
76
76
  const fileNames = [];
77
77
  if (project) {
78
- const sourceFile = (_p = (_o = project.project) === null || _o === void 0 ? void 0 : _o.getLanguageService().context.core.virtualFiles.get(shared.getPathOfUri(document.uri))) === null || _p === void 0 ? void 0 : _p[1];
78
+ const sourceFile = (_q = (_p = project.project) === null || _p === void 0 ? void 0 : _p.getLanguageService().context.core.virtualFiles.get(shared.getPathOfUri(document.uri))) === null || _q === void 0 ? void 0 : _q[1];
79
79
  if (sourceFile) {
80
80
  (0, language_core_1.forEachEmbeddedFile)(sourceFile, e => {
81
81
  if (e.snapshot.getLength() && e.kind === 1) {
@@ -87,16 +87,16 @@ function register(connection, projects) {
87
87
  return fileNames;
88
88
  }));
89
89
  connection.onRequest(protocol_1.GetVirtualFileRequest.type, (params) => __awaiter(this, void 0, void 0, function* () {
90
- var _q, _r, _s;
90
+ var _r, _s, _t;
91
91
  const project = yield projects.getProject(params.sourceFileUri);
92
92
  if (project) {
93
- const sourceAndVirtual = (_q = project.project) === null || _q === void 0 ? void 0 : _q.getLanguageService().context.core.virtualFiles.getSourceByVirtualFileName(params.virtualFileName);
93
+ const sourceAndVirtual = (_r = project.project) === null || _r === void 0 ? void 0 : _r.getLanguageService().context.core.virtualFiles.getSourceByVirtualFileName(params.virtualFileName);
94
94
  if (sourceAndVirtual) {
95
95
  const virtualFile = sourceAndVirtual[2];
96
96
  const mappings = {};
97
97
  for (const mapping of virtualFile.mappings) {
98
- const sourceUri = shared.getUriByPath((_r = mapping.source) !== null && _r !== void 0 ? _r : sourceAndVirtual[0]);
99
- (_s = mappings[sourceUri]) !== null && _s !== void 0 ? _s : (mappings[sourceUri] = []);
98
+ const sourceUri = shared.getUriByPath((_s = mapping.source) !== null && _s !== void 0 ? _s : sourceAndVirtual[0]);
99
+ (_t = mappings[sourceUri]) !== null && _t !== void 0 ? _t : (mappings[sourceUri] = []);
100
100
  mappings[sourceUri].push(mapping);
101
101
  }
102
102
  return {
@@ -110,11 +110,11 @@ function register(connection, projects) {
110
110
  projects.reloadProject();
111
111
  });
112
112
  connection.onNotification(protocol_1.WriteVirtualFilesNotification.type, (params) => __awaiter(this, void 0, void 0, function* () {
113
- var _t;
113
+ var _u;
114
114
  const fs = yield Promise.resolve().then(() => require('fs'));
115
115
  const project = yield projects.getProject(params.uri);
116
116
  if (project) {
117
- const ls = (_t = (yield project.project)) === null || _t === void 0 ? void 0 : _t.getLanguageServiceDontCreate();
117
+ const ls = (_u = (yield project.project)) === null || _u === void 0 ? void 0 : _u.getLanguageServiceDontCreate();
118
118
  if (ls) {
119
119
  const sourceFiles = new Set(ls.context.host.getScriptFileNames());
120
120
  for (const virtualFile of ls.context.core.typescript.languageServiceHost.getScriptFileNames()) {
@@ -19,6 +19,51 @@ function register(connection, projects, initParams, cancelHost, semanticTokensLe
19
19
  let lastCodeLensLs;
20
20
  let lastCodeActionLs;
21
21
  let lastCallHierarchyLs;
22
+ connection.onDocumentFormatting((params) => __awaiter(this, void 0, void 0, function* () {
23
+ return worker(params.textDocument.uri, vueLs => {
24
+ return vueLs.format(params.textDocument.uri, params.options);
25
+ });
26
+ }));
27
+ connection.onDocumentRangeFormatting((params) => __awaiter(this, void 0, void 0, function* () {
28
+ return worker(params.textDocument.uri, vueLs => {
29
+ return vueLs.format(params.textDocument.uri, params.options, params.range);
30
+ });
31
+ }));
32
+ connection.onDocumentOnTypeFormatting((params) => __awaiter(this, void 0, void 0, function* () {
33
+ return worker(params.textDocument.uri, vueLs => {
34
+ return vueLs.format(params.textDocument.uri, params.options, undefined, params);
35
+ });
36
+ }));
37
+ connection.onSelectionRanges((params) => __awaiter(this, void 0, void 0, function* () {
38
+ return worker(params.textDocument.uri, vueLs => {
39
+ return vueLs.getSelectionRanges(params.textDocument.uri, params.positions);
40
+ });
41
+ }));
42
+ connection.onFoldingRanges((params) => __awaiter(this, void 0, void 0, function* () {
43
+ return worker(params.textDocument.uri, vueLs => {
44
+ return vueLs.getFoldingRanges(params.textDocument.uri);
45
+ });
46
+ }));
47
+ connection.languages.onLinkedEditingRange((params) => __awaiter(this, void 0, void 0, function* () {
48
+ return worker(params.textDocument.uri, vueLs => {
49
+ return vueLs.findLinkedEditingRanges(params.textDocument.uri, params.position);
50
+ });
51
+ }));
52
+ connection.onDocumentSymbol((params) => __awaiter(this, void 0, void 0, function* () {
53
+ return worker(params.textDocument.uri, vueLs => {
54
+ return vueLs.findDocumentSymbols(params.textDocument.uri);
55
+ });
56
+ }));
57
+ connection.onDocumentColor((params) => __awaiter(this, void 0, void 0, function* () {
58
+ return worker(params.textDocument.uri, vueLs => {
59
+ return vueLs.findDocumentColors(params.textDocument.uri);
60
+ });
61
+ }));
62
+ connection.onColorPresentation((params) => __awaiter(this, void 0, void 0, function* () {
63
+ return worker(params.textDocument.uri, vueLs => {
64
+ return vueLs.getColorPresentations(params.textDocument.uri, params.color, params.range);
65
+ });
66
+ }));
22
67
  connection.onCompletion((params) => __awaiter(this, void 0, void 0, function* () {
23
68
  return worker(params.textDocument.uri, (vueLs) => __awaiter(this, void 0, void 0, function* () {
24
69
  lastCompleteUri = params.textDocument.uri;
@@ -9,7 +9,7 @@ export interface ProjectContext {
9
9
  workspace: WorkspaceContext;
10
10
  rootUri: URI;
11
11
  tsConfig: path.PosixPath | ts.CompilerOptions;
12
- documentRegistry: ts.DocumentRegistry;
12
+ documentRegistry: ts.DocumentRegistry | undefined;
13
13
  serverConfig: ServerConfig | undefined;
14
14
  }
15
15
  export type Project = ReturnType<typeof createProject>;
@@ -59,6 +59,16 @@ export declare function createProject(context: ProjectContext): Promise<{
59
59
  };
60
60
  languageServiceHost: embedded.LanguageServiceHost;
61
61
  getLanguageService: () => {
62
+ format: (uri: string, options: embeddedLS.FormattingOptions, range?: embeddedLS.Range | undefined, onTypeParams?: {
63
+ ch: string;
64
+ position: embeddedLS.Position;
65
+ } | undefined) => Promise<embeddedLS.TextEdit[] | undefined>;
66
+ getFoldingRanges: (uri: string) => Promise<embeddedLS.FoldingRange[] | undefined>;
67
+ getSelectionRanges: (uri: string, positions: embeddedLS.Position[]) => Promise<embeddedLS.SelectionRange[] | undefined>;
68
+ findLinkedEditingRanges: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.LinkedEditingRanges | undefined>;
69
+ findDocumentSymbols: (uri: string) => Promise<embeddedLS.SymbolInformation[] | undefined>;
70
+ findDocumentColors: (uri: string) => Promise<embeddedLS.ColorInformation[] | undefined>;
71
+ getColorPresentations: (uri: string, color: embeddedLS.Color, range: embeddedLS.Range) => Promise<embeddedLS.ColorPresentation[] | undefined>;
62
72
  doValidation: (uri: string, token?: embeddedLS.CancellationToken | undefined, response?: ((result: embeddedLS.Diagnostic[]) => void) | undefined) => Promise<embeddedLS.Diagnostic[]>;
63
73
  findReferences: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.Location[] | undefined>;
64
74
  findFileReferences: (uri: string) => embeddedLS.NullableResult<embeddedLS.Location[]>;
@@ -95,10 +105,20 @@ export declare function createProject(context: ProjectContext): Promise<{
95
105
  getIncomingCalls(item: embeddedLS.CallHierarchyItem): Promise<embeddedLS.CallHierarchyIncomingCall[]>;
96
106
  getOutgoingCalls(item: embeddedLS.CallHierarchyItem): Promise<embeddedLS.CallHierarchyOutgoingCall[]>;
97
107
  };
98
- dispose: () => void;
99
- context: embeddedLS.LanguageServiceRuntimeContext;
108
+ dispose: () => void | undefined;
109
+ context: embeddedLS.LanguageServiceRuntimeContext<embedded.LanguageServiceHost>;
100
110
  };
101
111
  getLanguageServiceDontCreate: () => {
112
+ format: (uri: string, options: embeddedLS.FormattingOptions, range?: embeddedLS.Range | undefined, onTypeParams?: {
113
+ ch: string;
114
+ position: embeddedLS.Position;
115
+ } | undefined) => Promise<embeddedLS.TextEdit[] | undefined>;
116
+ getFoldingRanges: (uri: string) => Promise<embeddedLS.FoldingRange[] | undefined>;
117
+ getSelectionRanges: (uri: string, positions: embeddedLS.Position[]) => Promise<embeddedLS.SelectionRange[] | undefined>;
118
+ findLinkedEditingRanges: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.LinkedEditingRanges | undefined>;
119
+ findDocumentSymbols: (uri: string) => Promise<embeddedLS.SymbolInformation[] | undefined>;
120
+ findDocumentColors: (uri: string) => Promise<embeddedLS.ColorInformation[] | undefined>;
121
+ getColorPresentations: (uri: string, color: embeddedLS.Color, range: embeddedLS.Range) => Promise<embeddedLS.ColorPresentation[] | undefined>;
102
122
  doValidation: (uri: string, token?: embeddedLS.CancellationToken | undefined, response?: ((result: embeddedLS.Diagnostic[]) => void) | undefined) => Promise<embeddedLS.Diagnostic[]>;
103
123
  findReferences: (uri: string, position: embeddedLS.Position) => Promise<embeddedLS.Location[] | undefined>;
104
124
  findFileReferences: (uri: string) => embeddedLS.NullableResult<embeddedLS.Location[]>;
@@ -135,8 +155,8 @@ export declare function createProject(context: ProjectContext): Promise<{
135
155
  getIncomingCalls(item: embeddedLS.CallHierarchyItem): Promise<embeddedLS.CallHierarchyIncomingCall[]>;
136
156
  getOutgoingCalls(item: embeddedLS.CallHierarchyItem): Promise<embeddedLS.CallHierarchyOutgoingCall[]>;
137
157
  };
138
- dispose: () => void;
139
- context: embeddedLS.LanguageServiceRuntimeContext;
158
+ dispose: () => void | undefined;
159
+ context: embeddedLS.LanguageServiceRuntimeContext<embedded.LanguageServiceHost>;
140
160
  } | undefined;
141
161
  getParsedCommandLine: () => ts.ParsedCommandLine;
142
162
  tryAddFile: (fileName: string) => void;
@@ -14,10 +14,23 @@ const embeddedLS = require("@volar/language-service");
14
14
  const shared = require("@volar/shared");
15
15
  const path = require("typesafe-path");
16
16
  const vscode = require("vscode-languageserver");
17
+ const types_1 = require("../types");
17
18
  const uriMap_1 = require("./utils/uriMap");
18
19
  function createProject(context) {
20
+ var _a;
19
21
  return __awaiter(this, void 0, void 0, function* () {
20
- const sys = context.workspace.workspaces.fileSystemHost.getWorkspaceFileSystem(context.rootUri);
22
+ const sys = context.workspace.workspaces.initOptions.serverMode === types_1.ServerMode.Syntactic || !context.workspace.workspaces.fileSystemHost
23
+ ? {
24
+ newLine: '\n',
25
+ useCaseSensitiveFileNames: false,
26
+ fileExists: () => false,
27
+ readFile: () => undefined,
28
+ readDirectory: () => [],
29
+ getCurrentDirectory: () => '',
30
+ realpath: () => '',
31
+ resolvePath: () => '',
32
+ }
33
+ : context.workspace.workspaces.fileSystemHost.getWorkspaceFileSystem(context.rootUri);
21
34
  let typeRootVersion = 0;
22
35
  let projectVersion = 0;
23
36
  let projectVersionUpdateTime = context.workspace.workspaces.cancelTokenHost.getMtime();
@@ -25,7 +38,7 @@ function createProject(context) {
25
38
  let parsedCommandLine = createParsedCommandLine(context.workspace.workspaces.ts, sys, shared.getPathOfUri(context.rootUri.toString()), context.tsConfig, context.workspace.workspaces.plugins);
26
39
  const scripts = (0, uriMap_1.createUriMap)();
27
40
  const languageServiceHost = createLanguageServiceHost();
28
- const disposeWatchEvent = context.workspace.workspaces.fileSystemHost.onDidChangeWatchedFiles(params => {
41
+ const disposeWatchEvent = (_a = context.workspace.workspaces.fileSystemHost) === null || _a === void 0 ? void 0 : _a.onDidChangeWatchedFiles(params => {
29
42
  onWorkspaceFilesChanged(params.changes);
30
43
  });
31
44
  const disposeDocChange = context.workspace.workspaces.documents.onDidChangeContent(() => {
@@ -50,7 +63,7 @@ function createProject(context) {
50
63
  };
51
64
  function getLanguageService() {
52
65
  if (!languageService) {
53
- const languageModules = context.workspace.workspaces.plugins.map(plugin => { var _a, _b, _c; return (_c = (_b = (_a = plugin.semanticService) === null || _a === void 0 ? void 0 : _a.getLanguageModules) === null || _b === void 0 ? void 0 : _b.call(_a, languageServiceHost)) !== null && _c !== void 0 ? _c : []; }).flat();
66
+ const languageModules = context.workspace.workspaces.plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.getLanguageModules) === null || _a === void 0 ? void 0 : _a.call(plugin, languageServiceHost)) !== null && _b !== void 0 ? _b : []; }).flat();
54
67
  const languageContext = embedded.createLanguageContext(languageServiceHost, languageModules);
55
68
  const languageServiceContext = embeddedLS.createLanguageServiceContext({
56
69
  host: languageServiceHost,
@@ -59,14 +72,16 @@ function createProject(context) {
59
72
  var _a, _b;
60
73
  return [
61
74
  ...(_b = (_a = context.serverConfig) === null || _a === void 0 ? void 0 : _a.plugins) !== null && _b !== void 0 ? _b : [],
62
- ...context.workspace.workspaces.plugins.map(plugin => { var _a, _b, _c; return (_c = (_b = (_a = plugin.semanticService) === null || _a === void 0 ? void 0 : _a.getServicePlugins) === null || _b === void 0 ? void 0 : _b.call(_a, languageServiceHost, languageService)) !== null && _c !== void 0 ? _c : []; }).flat(),
75
+ ...context.workspace.workspaces.plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.getLanguageServicePlugins) === null || _a === void 0 ? void 0 : _a.call(plugin, languageServiceHost, languageServiceContext)) !== null && _b !== void 0 ? _b : []; }).flat(),
63
76
  ];
64
77
  },
65
78
  env: {
66
79
  rootUri: context.rootUri,
67
80
  configurationHost: context.workspace.workspaces.configurationHost,
68
81
  fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
69
- documentContext: getHTMLDocumentContext(context.workspace.workspaces.ts, languageServiceHost),
82
+ documentContext: context.workspace.workspaces.ts
83
+ ? getHTMLDocumentContext(context.workspace.workspaces.ts, languageServiceHost)
84
+ : undefined,
70
85
  schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
71
86
  const protocol = uri.substring(0, uri.indexOf(':'));
72
87
  const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
@@ -77,6 +92,7 @@ function createProject(context) {
77
92
  }),
78
93
  },
79
94
  documentRegistry: context.documentRegistry,
95
+ getLanguageService: () => languageService,
80
96
  });
81
97
  languageService = embeddedLS.createLanguageService(languageServiceContext);
82
98
  }
@@ -115,7 +131,6 @@ function createProject(context) {
115
131
  });
116
132
  }
117
133
  function createLanguageServiceHost() {
118
- var _a;
119
134
  const token = {
120
135
  isCancellationRequested() {
121
136
  return context.workspace.workspaces.cancelTokenHost.getMtime() !== projectVersionUpdateTime;
@@ -138,13 +153,16 @@ function createProject(context) {
138
153
  getCancellationToken: () => token,
139
154
  // custom
140
155
  getDefaultLibFileName: options => {
141
- try {
142
- return context.workspace.workspaces.ts.getDefaultLibFilePath(options);
143
- }
144
- catch (_a) {
145
- // web
146
- return context.workspace.workspaces.initOptions.typescript.tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
156
+ if (context.workspace.workspaces.initOptions.typescript && context.workspace.workspaces.ts) {
157
+ try {
158
+ return context.workspace.workspaces.ts.getDefaultLibFilePath(options);
159
+ }
160
+ catch (_a) {
161
+ // web
162
+ return context.workspace.workspaces.initOptions.typescript.tsdk + '/' + context.workspace.workspaces.ts.getDefaultLibFileName(options);
163
+ }
147
164
  }
165
+ return '';
148
166
  },
149
167
  getProjectVersion: () => projectVersion.toString(),
150
168
  getTypeRootsVersion: () => typeRootVersion,
@@ -152,7 +170,9 @@ function createProject(context) {
152
170
  getCompilationSettings: () => parsedCommandLine.options,
153
171
  getScriptVersion,
154
172
  getScriptSnapshot,
155
- getTypeScriptModule: () => context.workspace.workspaces.ts,
173
+ getTypeScriptModule: () => {
174
+ return context.workspace.workspaces.ts;
175
+ },
156
176
  };
157
177
  if (context.workspace.workspaces.initOptions.noProjectReferences) {
158
178
  host.getProjectReferences = undefined;
@@ -162,8 +182,8 @@ function createProject(context) {
162
182
  host.getLocalizedDiagnosticMessages = () => context.workspace.workspaces.tsLocalized;
163
183
  }
164
184
  for (const plugin of context.workspace.workspaces.plugins) {
165
- if ((_a = plugin.semanticService) === null || _a === void 0 ? void 0 : _a.resolveLanguageServiceHost) {
166
- host = plugin.semanticService.resolveLanguageServiceHost(context.workspace.workspaces.ts, sys, context.tsConfig, host);
185
+ if (context.workspace.workspaces.ts && plugin.resolveLanguageServiceHost) {
186
+ host = plugin.resolveLanguageServiceHost(context.workspace.workspaces.ts, sys, context.tsConfig, host);
167
187
  }
168
188
  }
169
189
  return host;
@@ -185,7 +205,7 @@ function createProject(context) {
185
205
  if (script && script.snapshotVersion === script.version) {
186
206
  return script.snapshot;
187
207
  }
188
- if (sys.fileExists(fileName)) {
208
+ if (context.workspace.workspaces.ts && sys.fileExists(fileName)) {
189
209
  if (context.workspace.workspaces.initOptions.maxFileSize) {
190
210
  const fileSize = (_a = sys.getFileSize) === null || _a === void 0 ? void 0 : _a.call(sys, fileName);
191
211
  if (fileSize !== undefined && fileSize > context.workspace.workspaces.initOptions.maxFileSize) {
@@ -216,38 +236,40 @@ function createProject(context) {
216
236
  function dispose() {
217
237
  languageService === null || languageService === void 0 ? void 0 : languageService.dispose();
218
238
  scripts.clear();
219
- disposeWatchEvent();
239
+ disposeWatchEvent === null || disposeWatchEvent === void 0 ? void 0 : disposeWatchEvent();
220
240
  disposeDocChange();
221
241
  }
222
242
  });
223
243
  }
224
244
  exports.createProject = createProject;
225
245
  function createParsedCommandLine(ts, sys, rootPath, tsConfig, plugins) {
226
- const extraFileExtensions = plugins.map(plugin => plugin.extraFileExtensions).flat();
227
- try {
228
- let content;
229
- if (typeof tsConfig === 'string') {
230
- const config = ts.readJsonConfigFile(tsConfig, sys.readFile);
231
- content = ts.parseJsonSourceFileConfigFileContent(config, sys, path.dirname(tsConfig), {}, tsConfig, undefined, extraFileExtensions);
246
+ const extraFileExtensions = plugins.map(plugin => { var _a; return (_a = plugin.extraFileExtensions) !== null && _a !== void 0 ? _a : []; }).flat();
247
+ if (ts) {
248
+ try {
249
+ let content;
250
+ if (typeof tsConfig === 'string') {
251
+ const config = ts.readJsonConfigFile(tsConfig, sys.readFile);
252
+ content = ts.parseJsonSourceFileConfigFileContent(config, sys, path.dirname(tsConfig), {}, tsConfig, undefined, extraFileExtensions);
253
+ }
254
+ else {
255
+ content = ts.parseJsonConfigFileContent({ files: [] }, sys, rootPath, tsConfig, path.join(rootPath, 'jsconfig.json'), undefined, extraFileExtensions);
256
+ }
257
+ // fix https://github.com/johnsoncodehk/volar/issues/1786
258
+ // https://github.com/microsoft/TypeScript/issues/30457
259
+ // patching ts server broke with outDir + rootDir + composite/incremental
260
+ content.options.outDir = undefined;
261
+ content.fileNames = content.fileNames.map(shared.normalizeFileName);
262
+ return content;
232
263
  }
233
- else {
234
- content = ts.parseJsonConfigFileContent({ files: [] }, sys, rootPath, tsConfig, path.join(rootPath, 'jsconfig.json'), undefined, extraFileExtensions);
264
+ catch (_a) {
265
+ // will be failed if web fs host first result not ready
235
266
  }
236
- // fix https://github.com/johnsoncodehk/volar/issues/1786
237
- // https://github.com/microsoft/TypeScript/issues/30457
238
- // patching ts server broke with outDir + rootDir + composite/incremental
239
- content.options.outDir = undefined;
240
- content.fileNames = content.fileNames.map(shared.normalizeFileName);
241
- return content;
242
- }
243
- catch (_a) {
244
- // will be failed if web fs host first result not ready
245
- return {
246
- errors: [],
247
- fileNames: [],
248
- options: {},
249
- };
250
267
  }
268
+ return {
269
+ errors: [],
270
+ fileNames: [],
271
+ options: {},
272
+ };
251
273
  }
252
274
  function getHTMLDocumentContext(ts, host) {
253
275
  const documentContext = {
@@ -5,4 +5,4 @@ export interface ServerContext {
5
5
  runtimeEnv: RuntimeEnvironment;
6
6
  plugins: LanguageServerPlugin[];
7
7
  }
8
- export declare function createCommonLanguageServer(context: ServerContext): void;
8
+ export declare function startCommonLanguageServer(context: ServerContext): void;
@@ -8,28 +8,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.createCommonLanguageServer = void 0;
11
+ exports.startCommonLanguageServer = void 0;
12
12
  const vscode = require("vscode-languageserver");
13
13
  const vscode_uri_1 = require("vscode-uri");
14
14
  const types_1 = require("../types");
15
15
  const cancellationPipe_1 = require("./cancellationPipe");
16
16
  const configurationHost_1 = require("./configurationHost");
17
17
  const documents_1 = require("./documents");
18
- const syntaxServicesHost_1 = require("./syntaxServicesHost");
19
18
  const registerFeatures_1 = require("./utils/registerFeatures");
20
19
  const workspaces_1 = require("./workspaces");
21
- function createCommonLanguageServer(context) {
20
+ function startCommonLanguageServer(context) {
22
21
  let initParams;
23
22
  let options;
24
23
  let roots = [];
25
24
  let fsHost;
26
25
  let projects;
27
- let documentServiceHost;
28
26
  let configurationHost;
29
27
  let plugins;
30
28
  const documents = (0, documents_1.createDocuments)(context.connection);
31
29
  context.connection.onInitialize((_params) => __awaiter(this, void 0, void 0, function* () {
32
- var _a, _b, _c, _d;
30
+ var _a, _b, _c;
33
31
  initParams = _params;
34
32
  options = initParams.initializationOptions;
35
33
  plugins = context.plugins.map(plugin => plugin(options));
@@ -48,13 +46,8 @@ function createCommonLanguageServer(context) {
48
46
  },
49
47
  };
50
48
  configurationHost = ((_c = initParams.capabilities.workspace) === null || _c === void 0 ? void 0 : _c.configuration) ? (0, configurationHost_1.createConfigurationHost)(initParams, context.connection) : undefined;
51
- const serverMode = (_d = options.serverMode) !== null && _d !== void 0 ? _d : types_1.ServerMode.Semantic;
52
- (0, registerFeatures_1.setupSyntacticCapabilities)(initParams.capabilities, result.capabilities, options);
53
- yield _createDocumentServiceHost();
54
- if (serverMode === types_1.ServerMode.Semantic) {
55
- (0, registerFeatures_1.setupSemanticCapabilities)(initParams.capabilities, result.capabilities, options, plugins, getSemanticTokensLegend());
56
- yield createLanguageServiceHost();
57
- }
49
+ (0, registerFeatures_1.setupCapabilities)(initParams.capabilities, result.capabilities, options, plugins, getSemanticTokensLegend());
50
+ yield createLanguageServiceHost();
58
51
  try {
59
52
  // show version on LSP logs
60
53
  const packageJson = require('../package.json');
@@ -63,7 +56,7 @@ function createCommonLanguageServer(context) {
63
56
  version: packageJson.version,
64
57
  };
65
58
  }
66
- catch (_e) { }
59
+ catch (_d) { }
67
60
  return result;
68
61
  }));
69
62
  context.connection.onInitialized(() => {
@@ -73,11 +66,9 @@ function createCommonLanguageServer(context) {
73
66
  if ((_a = initParams.capabilities.workspace) === null || _a === void 0 ? void 0 : _a.workspaceFolders) {
74
67
  context.connection.workspace.onDidChangeWorkspaceFolders(e => {
75
68
  for (const folder of e.added) {
76
- documentServiceHost === null || documentServiceHost === void 0 ? void 0 : documentServiceHost.add(vscode_uri_1.URI.parse(folder.uri));
77
69
  projects === null || projects === void 0 ? void 0 : projects.add(vscode_uri_1.URI.parse(folder.uri));
78
70
  }
79
71
  for (const folder of e.removed) {
80
- documentServiceHost === null || documentServiceHost === void 0 ? void 0 : documentServiceHost.remove(vscode_uri_1.URI.parse(folder.uri));
81
72
  projects === null || projects === void 0 ? void 0 : projects.remove(vscode_uri_1.URI.parse(folder.uri));
82
73
  }
83
74
  });
@@ -98,7 +89,7 @@ function createCommonLanguageServer(context) {
98
89
  'jsx',
99
90
  'tsx',
100
91
  'json',
101
- ...plugins.map(plugin => plugin.extraFileExtensions.map(ext => ext.extension)).flat(),
92
+ ...plugins.map(plugin => { var _a, _b; return (_b = (_a = plugin.extraFileExtensions) === null || _a === void 0 ? void 0 : _a.map(ext => ext.extension)) !== null && _b !== void 0 ? _b : []; }).flat(),
102
93
  ].join(',')}}`
103
94
  },
104
95
  ]
@@ -106,26 +97,12 @@ function createCommonLanguageServer(context) {
106
97
  }
107
98
  });
108
99
  context.connection.listen();
109
- function _createDocumentServiceHost() {
110
- var _a, _b;
111
- return __awaiter(this, void 0, void 0, function* () {
112
- const ts = context.runtimeEnv.loadTypescript(options.typescript.tsdk);
113
- documentServiceHost = (0, syntaxServicesHost_1.createSyntaxServicesHost)(context.runtimeEnv, plugins, ts, configurationHost, options);
114
- for (const root of roots) {
115
- documentServiceHost.add(root);
116
- }
117
- (yield Promise.resolve().then(() => require('./features/documentFeatures'))).register(context.connection, documents, documentServiceHost);
118
- for (const plugin of plugins) {
119
- (_b = (_a = plugin.syntacticService) === null || _a === void 0 ? void 0 : _a.onInitialize) === null || _b === void 0 ? void 0 : _b.call(_a, context.connection);
120
- }
121
- });
122
- }
123
100
  function createLanguageServiceHost() {
124
- var _a, _b;
101
+ var _a;
125
102
  return __awaiter(this, void 0, void 0, function* () {
126
- const ts = context.runtimeEnv.loadTypescript(options.typescript.tsdk);
127
- fsHost = context.runtimeEnv.createFileSystemHost(ts, initParams.capabilities);
128
- const tsLocalized = initParams.locale ? yield context.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
103
+ const ts = options.typescript ? context.runtimeEnv.loadTypescript(options.typescript.tsdk) : undefined;
104
+ fsHost = ts ? context.runtimeEnv.createFileSystemHost(ts, initParams.capabilities) : undefined;
105
+ const tsLocalized = options.typescript && initParams.locale ? yield context.runtimeEnv.loadTypescriptLocalized(options.typescript.tsdk, initParams.locale) : undefined;
129
106
  const cancelTokenHost = (0, cancellationPipe_1.createCancellationTokenHost)(options.cancellationPipeName);
130
107
  const _projects = (0, workspaces_1.createWorkspaces)({
131
108
  server: context,
@@ -146,7 +123,7 @@ function createCommonLanguageServer(context) {
146
123
  (yield Promise.resolve().then(() => require('./features/customFeatures'))).register(context.connection, projects);
147
124
  (yield Promise.resolve().then(() => require('./features/languageFeatures'))).register(context.connection, projects, initParams, cancelTokenHost, getSemanticTokensLegend());
148
125
  for (const plugin of plugins) {
149
- (_b = (_a = plugin.semanticService) === null || _a === void 0 ? void 0 : _a.onInitialize) === null || _b === void 0 ? void 0 : _b.call(_a, context.connection, getLanguageService);
126
+ (_a = plugin.onInitialize) === null || _a === void 0 ? void 0 : _a.call(plugin, context.connection, getLanguageService);
150
127
  }
151
128
  function getLanguageService(uri) {
152
129
  var _a;
@@ -167,7 +144,7 @@ function createCommonLanguageServer(context) {
167
144
  };
168
145
  }
169
146
  }
170
- exports.createCommonLanguageServer = createCommonLanguageServer;
147
+ exports.startCommonLanguageServer = startCommonLanguageServer;
171
148
  // https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#standard-token-types-and-modifiers
172
149
  const standardSemanticTokensLegend = {
173
150
  tokenTypes: [
@@ -1,3 +1,3 @@
1
1
  import { ConfigurationHost } from '@volar/language-service';
2
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
3
- export declare function getInferredCompilerOptions(ts: typeof import('typescript/lib/tsserverlibrary'), configurationHost: ConfigurationHost | undefined): Promise<ts.CompilerOptions>;
3
+ export declare function getInferredCompilerOptions(configurationHost: ConfigurationHost | undefined): Promise<ts.CompilerOptions>;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.getInferredCompilerOptions = void 0;
12
- function getInferredCompilerOptions(ts, configurationHost) {
12
+ function getInferredCompilerOptions(configurationHost) {
13
13
  return __awaiter(this, void 0, void 0, function* () {
14
14
  let [implicitProjectConfig_1, implicitProjectConfig_2] = yield Promise.all([
15
15
  configurationHost === null || configurationHost === void 0 ? void 0 : configurationHost.getConfiguration('js/ts.implicitProjectConfig'),
@@ -21,7 +21,7 @@ function getInferredCompilerOptions(ts, configurationHost) {
21
21
  const experimentalDecorators = readExperimentalDecorators();
22
22
  const strictNullChecks = readImplicitStrictNullChecks();
23
23
  const strictFunctionTypes = readImplicitStrictFunctionTypes();
24
- const options = Object.assign(Object.assign({}, inferredProjectCompilerOptions('typescript')), { allowJs: true, allowSyntheticDefaultImports: true, allowNonTsExtensions: true, resolveJsonModule: true, jsx: ts.JsxEmit.Preserve });
24
+ const options = Object.assign(Object.assign({}, inferredProjectCompilerOptions('typescript')), { allowJs: true, allowSyntheticDefaultImports: true, allowNonTsExtensions: true, resolveJsonModule: true, jsx: 1 /* ts.JsxEmit.Preserve */ });
25
25
  return options;
26
26
  function readCheckJs() {
27
27
  var _a, _b;
@@ -41,9 +41,9 @@ function getInferredCompilerOptions(ts, configurationHost) {
41
41
  }
42
42
  function inferredProjectCompilerOptions(projectType) {
43
43
  const projectConfig = {
44
- module: ts.ModuleKind.CommonJS,
45
- target: ts.ScriptTarget.ES2020,
46
- jsx: ts.JsxEmit.Preserve,
44
+ module: 1 /* ts.ModuleKind.CommonJS */,
45
+ target: 7 /* ts.ScriptTarget.ES2020 */,
46
+ jsx: 1 /* ts.JsxEmit.Preserve */,
47
47
  };
48
48
  if (checkJs) {
49
49
  projectConfig.checkJs = true;
@@ -1,5 +1,4 @@
1
1
  import { LanguageServerPlugin, LanguageServerInitializationOptions } from '../../types';
2
2
  import * as vscode from 'vscode-languageserver';
3
3
  import { ClientCapabilities } from 'vscode-languageserver';
4
- export declare function setupSyntacticCapabilities(params: ClientCapabilities, server: vscode.ServerCapabilities, initOptions: LanguageServerInitializationOptions): void;
5
- export declare function setupSemanticCapabilities(params: ClientCapabilities, server: vscode.ServerCapabilities, initOptions: LanguageServerInitializationOptions, plugins: ReturnType<LanguageServerPlugin>[], semanticTokensLegend: vscode.SemanticTokensLegend): void;
4
+ export declare function setupCapabilities(params: ClientCapabilities, server: vscode.ServerCapabilities, initOptions: LanguageServerInitializationOptions, plugins: ReturnType<LanguageServerPlugin>[], semanticTokensLegend: vscode.SemanticTokensLegend): void;