@volar/language-server 1.2.0-alpha.9 → 1.3.0-alpha.1

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.
@@ -16,6 +16,7 @@ const workspace_1 = require("./workspace");
16
16
  const isFileInDir_1 = require("./utils/isFileInDir");
17
17
  function createWorkspaces(context) {
18
18
  var _a, _b, _c;
19
+ const uriToFileName = context.server.runtimeEnv.uriToFileName;
19
20
  const workspaces = new Map();
20
21
  let semanticTokensReq = 0;
21
22
  let documentUpdatedReq = 0;
@@ -139,8 +140,8 @@ function createWorkspaces(context) {
139
140
  var _a;
140
141
  return __awaiter(this, void 0, void 0, function* () {
141
142
  let rootUris = [...workspaces.keys()]
142
- .filter(rootUri => (0, isFileInDir_1.isFileInDir)(shared.uriToFileName(uri), shared.uriToFileName(rootUri)))
143
- .sort((a, b) => (0, workspace_1.sortTsConfigs)(shared.uriToFileName(uri), shared.uriToFileName(a), shared.uriToFileName(b)));
143
+ .filter(rootUri => (0, isFileInDir_1.isFileInDir)(uriToFileName(uri), uriToFileName(rootUri)))
144
+ .sort((a, b) => (0, workspace_1.sortTsConfigs)(uriToFileName(uri), uriToFileName(a), uriToFileName(b)));
144
145
  if (context.initOptions.serverMode !== types_1.ServerMode.Syntactic) {
145
146
  for (const rootUri of rootUris) {
146
147
  const workspace = yield workspaces.get(rootUri);
@@ -155,7 +156,7 @@ function createWorkspaces(context) {
155
156
  }
156
157
  if (rootUris.length) {
157
158
  const project = yield ((_a = (yield workspaces.get(rootUris[0]))) === null || _a === void 0 ? void 0 : _a.getInferredProject());
158
- project === null || project === void 0 ? void 0 : project.tryAddFile(shared.uriToFileName(uri));
159
+ project === null || project === void 0 ? void 0 : project.tryAddFile(uriToFileName(uri));
159
160
  return {
160
161
  tsconfig: undefined,
161
162
  project,
@@ -1,3 +1,3 @@
1
1
  import * as vscode from 'vscode-languageserver';
2
- import { FileSystemHost } from '../types';
3
- export declare function createNodeFileSystemHost(ts: typeof import('typescript/lib/tsserverlibrary'), capabilities: vscode.ClientCapabilities): FileSystemHost;
2
+ import { FileSystemHost, LanguageServerInitializationOptions, RuntimeEnvironment } from '../types';
3
+ export declare function createNodeFileSystemHost(ts: typeof import('typescript/lib/tsserverlibrary'), capabilities: vscode.ClientCapabilities, env: RuntimeEnvironment, _initOptions: LanguageServerInitializationOptions): FileSystemHost;
@@ -9,12 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.createNodeFileSystemHost = void 0;
12
- const shared = require("@volar/shared");
13
12
  const vscode = require("vscode-languageserver");
14
13
  const uriMap_1 = require("../common/utils/uriMap");
15
14
  let currentCwd = '';
16
- function createNodeFileSystemHost(ts, capabilities) {
17
- const instances = (0, uriMap_1.createUriMap)();
15
+ function createNodeFileSystemHost(ts, capabilities, env, _initOptions) {
16
+ const instances = (0, uriMap_1.createUriMap)(env.fileNameToUri);
18
17
  const onDidChangeWatchedFilesCb = new Set();
19
18
  return {
20
19
  ready(connection) {
@@ -51,7 +50,7 @@ function createNodeFileSystemHost(ts, capabilities) {
51
50
  };
52
51
  function createWorkspaceFileSystem(ts, capabilities, rootUri) {
53
52
  var _a;
54
- const rootPath = shared.uriToFileName(rootUri.toString());
53
+ const rootPath = env.uriToFileName(rootUri.toString());
55
54
  const workspaceSys = new Proxy(ts.sys, {
56
55
  get(target, prop) {
57
56
  const fn = target[prop];
package/out/node/index.js CHANGED
@@ -23,7 +23,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.startLanguageServer = exports.createConnection = void 0;
26
- const shared = require("@volar/shared");
27
26
  const fs = require("fs");
28
27
  const request_light_1 = require("request-light");
29
28
  const html = require("vscode-html-languageservice");
@@ -32,84 +31,91 @@ const server_1 = require("../common/server");
32
31
  const file_1 = require("../common/schemaRequestHandlers/file");
33
32
  const http_1 = require("../common/schemaRequestHandlers/http");
34
33
  const fileSystem_1 = require("./fileSystem");
34
+ const vscode_uri_1 = require("vscode-uri");
35
35
  __exportStar(require("../index"), exports);
36
36
  function createConnection() {
37
37
  return vscode.createConnection(vscode.ProposedFeatures.all);
38
38
  }
39
39
  exports.createConnection = createConnection;
40
40
  function startLanguageServer(connection, ...plugins) {
41
- (0, server_1.startCommonLanguageServer)({
42
- plugins,
43
- connection,
44
- runtimeEnv: {
45
- timer: {
46
- setImmediate(callback, ...args) {
47
- const handle = setImmediate(callback, ...args);
48
- return { dispose: () => clearImmediate(handle) };
41
+ const uriToFileName = (uri) => vscode_uri_1.URI.parse(uri).fsPath.replace(/\\/g, '/');
42
+ const fileNameToUri = (fileName) => vscode_uri_1.URI.file(fileName).toString();
43
+ (0, server_1.startCommonLanguageServer)(connection, () => {
44
+ return {
45
+ plugins,
46
+ connection,
47
+ runtimeEnv: {
48
+ uriToFileName,
49
+ fileNameToUri,
50
+ timer: {
51
+ setImmediate(callback, ...args) {
52
+ const handle = setImmediate(callback, ...args);
53
+ return { dispose: () => clearImmediate(handle) };
54
+ },
49
55
  },
50
- },
51
- loadTypescript(tsdk) {
52
- for (const name of ['./typescript.js', './tsserverlibrary.js', './tsserver.js']) {
53
- try {
54
- const path = require.resolve(name, { paths: [tsdk] });
55
- return require(path);
56
- }
57
- catch (_a) { }
58
- }
59
- },
60
- loadTypescriptLocalized(tsdk, locale) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- try {
63
- const path = require.resolve(`./${locale}/diagnosticMessages.generated.json`, { paths: [tsdk] });
64
- return require(path);
56
+ loadTypescript(tsdk) {
57
+ for (const name of ['./typescript.js', './tsserverlibrary.js', './tsserver.js']) {
58
+ try {
59
+ const path = require.resolve(name, { paths: [tsdk] });
60
+ return require(path);
61
+ }
62
+ catch (_a) { }
65
63
  }
66
- catch (_a) { }
67
- });
68
- },
69
- schemaRequestHandlers: {
70
- file: file_1.default,
71
- http: http_1.default,
72
- https: http_1.default,
73
- },
74
- onDidChangeConfiguration(settings) {
75
- (0, request_light_1.configure)(settings.http && settings.http.proxy, settings.http && settings.http.proxyStrictSSL);
76
- },
77
- createFileSystemHost: fileSystem_1.createNodeFileSystemHost,
78
- fileSystemProvide: {
79
- stat: (uri) => {
80
- return new Promise((resolve, reject) => {
81
- fs.stat(shared.uriToFileName(uri), (err, stats) => {
82
- if (stats) {
83
- resolve({
84
- type: stats.isFile() ? html.FileType.File
85
- : stats.isDirectory() ? html.FileType.Directory
86
- : stats.isSymbolicLink() ? html.FileType.SymbolicLink
87
- : html.FileType.Unknown,
88
- ctime: stats.ctimeMs,
89
- mtime: stats.mtimeMs,
90
- size: stats.size,
91
- });
92
- }
93
- else {
94
- reject(err);
95
- }
96
- });
64
+ },
65
+ loadTypescriptLocalized(tsdk, locale) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ try {
68
+ const path = require.resolve(`./${locale}/diagnosticMessages.generated.json`, { paths: [tsdk] });
69
+ return require(path);
70
+ }
71
+ catch (_a) { }
97
72
  });
98
73
  },
99
- readDirectory: (uri) => {
100
- return new Promise((resolve, reject) => {
101
- fs.readdir(shared.uriToFileName(uri), (err, files) => {
102
- if (files) {
103
- resolve(files.map(file => [file, html.FileType.File]));
104
- }
105
- else {
106
- reject(err);
107
- }
74
+ schemaRequestHandlers: {
75
+ file: file_1.default,
76
+ http: http_1.default,
77
+ https: http_1.default,
78
+ },
79
+ onDidChangeConfiguration(settings) {
80
+ (0, request_light_1.configure)(settings.http && settings.http.proxy, settings.http && settings.http.proxyStrictSSL);
81
+ },
82
+ createFileSystemHost: fileSystem_1.createNodeFileSystemHost,
83
+ fileSystemProvide: {
84
+ stat: (uri) => {
85
+ return new Promise((resolve, reject) => {
86
+ fs.stat(uriToFileName(uri), (err, stats) => {
87
+ if (stats) {
88
+ resolve({
89
+ type: stats.isFile() ? html.FileType.File
90
+ : stats.isDirectory() ? html.FileType.Directory
91
+ : stats.isSymbolicLink() ? html.FileType.SymbolicLink
92
+ : html.FileType.Unknown,
93
+ ctime: stats.ctimeMs,
94
+ mtime: stats.mtimeMs,
95
+ size: stats.size,
96
+ });
97
+ }
98
+ else {
99
+ reject(err);
100
+ }
101
+ });
108
102
  });
109
- });
103
+ },
104
+ readDirectory: (uri) => {
105
+ return new Promise((resolve, reject) => {
106
+ fs.readdir(uriToFileName(uri), (err, files) => {
107
+ if (files) {
108
+ resolve(files.map(file => [file, html.FileType.File]));
109
+ }
110
+ else {
111
+ reject(err);
112
+ }
113
+ });
114
+ });
115
+ },
110
116
  },
111
117
  },
112
- },
118
+ };
113
119
  });
114
120
  }
115
121
  exports.startLanguageServer = startLanguageServer;
package/out/protocol.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as vscode from 'vscode-languageserver-protocol';
2
2
  import type * as html from 'vscode-html-languageservice';
3
- import type { FileRangeCapabilities } from '@volar/language-core';
3
+ import type { FileKind, FileRangeCapabilities } from '@volar/language-core';
4
4
  /**
5
5
  * Server request client
6
6
  */
@@ -10,11 +10,8 @@ export declare namespace ShowReferencesNotification {
10
10
  };
11
11
  const type: vscode.NotificationType<ResponseType>;
12
12
  }
13
- export declare namespace FsStatRequest {
14
- const type: vscode.RequestType<string, html.FileStat | null | undefined, unknown>;
15
- }
16
13
  export declare namespace FsReadFileRequest {
17
- const type: vscode.RequestType<string, string | null | undefined, unknown>;
14
+ const type: vscode.RequestType<string, Uint8Array | null | undefined, unknown>;
18
15
  }
19
16
  export declare namespace FsReadDirectoryRequest {
20
17
  const type: vscode.RequestType<string, [string, html.FileType][], unknown>;
@@ -60,10 +57,12 @@ export declare namespace ReloadProjectNotification {
60
57
  const type: vscode.NotificationType<vscode.TextDocumentIdentifier>;
61
58
  }
62
59
  export declare namespace GetVirtualFileNamesRequest {
63
- type ParamsType = vscode.TextDocumentIdentifier;
60
+ type ParamsType = vscode.TextDocumentIdentifier & {
61
+ fileKinds?: FileKind[];
62
+ };
64
63
  type ResponseType = string[];
65
64
  type ErrorType = never;
66
- const type: vscode.RequestType<vscode.TextDocumentIdentifier, ResponseType, never>;
65
+ const type: vscode.RequestType<ParamsType, ResponseType, never>;
67
66
  }
68
67
  export declare namespace GetVirtualFileRequest {
69
68
  type ParamsType = {
package/out/protocol.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.ReportStats = exports.GetVirtualFileRequest = exports.GetVirtualFileNamesRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = exports.FsReadDirectoryRequest = exports.FsReadFileRequest = exports.FsStatRequest = exports.ShowReferencesNotification = void 0;
2
+ exports.ReportStats = exports.GetVirtualFileRequest = exports.GetVirtualFileNamesRequest = exports.ReloadProjectNotification = exports.WriteVirtualFilesNotification = exports.AutoInsertRequest = exports.GetMatchTsConfigRequest = exports.FindFileReferenceRequest = exports.FsReadDirectoryRequest = exports.FsReadFileRequest = exports.ShowReferencesNotification = void 0;
3
3
  const vscode = require("vscode-languageserver-protocol");
4
4
  /**
5
5
  * Server request client
@@ -8,10 +8,6 @@ var ShowReferencesNotification;
8
8
  (function (ShowReferencesNotification) {
9
9
  ShowReferencesNotification.type = new vscode.NotificationType('volar/server/showReferences');
10
10
  })(ShowReferencesNotification = exports.ShowReferencesNotification || (exports.ShowReferencesNotification = {}));
11
- var FsStatRequest;
12
- (function (FsStatRequest) {
13
- FsStatRequest.type = new vscode.RequestType('volar/server/fs/stat');
14
- })(FsStatRequest = exports.FsStatRequest || (exports.FsStatRequest = {}));
15
11
  var FsReadFileRequest;
16
12
  (function (FsReadFileRequest) {
17
13
  FsReadFileRequest.type = new vscode.RequestType('volar/server/fs/readFile');
package/out/types.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /// <reference types="node" />
2
- import * as embeddedLS from '@volar/language-service';
2
+ import { LanguageService, LanguageServiceOptions } from '@volar/language-service';
3
3
  import * as embedded from '@volar/language-core';
4
4
  import type { FileSystemProvider } from 'vscode-html-languageservice';
5
5
  import type * as ts from 'typescript/lib/tsserverlibrary';
6
6
  import * as vscode from 'vscode-languageserver';
7
7
  import { URI } from 'vscode-uri';
8
- import { Config, LanguageServicePluginContext } from '@volar/language-service';
8
+ import { Config } from '@volar/language-service';
9
9
  import { ProjectContext } from './common/project';
10
10
  export type FileSystemHost = {
11
11
  ready(connection: vscode.Connection): void;
@@ -15,35 +15,39 @@ export type FileSystemHost = {
15
15
  };
16
16
  export type FileSystem = Pick<ts.System, 'newLine' | 'useCaseSensitiveFileNames' | 'fileExists' | 'readFile' | 'readDirectory' | 'getCurrentDirectory' | 'realpath' | 'resolvePath'> & Partial<ts.System>;
17
17
  export interface RuntimeEnvironment {
18
+ uriToFileName: (uri: string) => string;
19
+ fileNameToUri: (fileName: string) => string;
18
20
  loadTypescript: (tsdk: string) => typeof import('typescript/lib/tsserverlibrary');
19
21
  loadTypescriptLocalized: (tsdk: string, locale: string) => Promise<{} | undefined>;
20
22
  schemaRequestHandlers: {
21
- [schema: string]: (uri: string, encoding?: BufferEncoding) => Promise<string>;
23
+ [schema: string]: undefined | ((uri: string, encoding?: BufferEncoding) => Promise<string | undefined>);
22
24
  };
23
25
  onDidChangeConfiguration?: (settings: any) => void;
24
26
  fileSystemProvide: FileSystemProvider | undefined;
25
- createFileSystemHost: (ts: typeof import('typescript/lib/tsserverlibrary'), capabilities: vscode.ClientCapabilities) => FileSystemHost;
27
+ createFileSystemHost: (ts: typeof import('typescript/lib/tsserverlibrary'), capabilities: vscode.ClientCapabilities, env: RuntimeEnvironment, initOptions: LanguageServerInitializationOptions) => FileSystemHost;
26
28
  readonly timer: {
27
29
  setImmediate(callback: (...args: any[]) => void, ...args: any[]): vscode.Disposable;
28
30
  };
29
31
  }
30
32
  export interface LanguageServiceContext {
31
33
  project: ProjectContext;
32
- env: LanguageServicePluginContext['env'];
34
+ options: LanguageServiceOptions;
33
35
  host: embedded.LanguageServiceHost;
34
36
  sys: FileSystem;
35
37
  }
36
- export type LanguageServerPlugin<A extends LanguageServerInitializationOptions = LanguageServerInitializationOptions, C = embeddedLS.LanguageService> = (initOptions: A) => {
37
- tsconfigExtraFileExtensions: ts.FileExtensionInfo[];
38
- diagnosticDocumentSelector: vscode.DocumentSelector;
39
- extensions: {
40
- fileRenameOperationFilter: string[];
41
- fileWatcher: string[];
38
+ export interface LanguageServerPlugin {
39
+ (initOptions: LanguageServerInitializationOptions): {
40
+ tsconfigExtraFileExtensions: ts.FileExtensionInfo[];
41
+ diagnosticDocumentSelector: vscode.DocumentSelector;
42
+ extensions: {
43
+ fileRenameOperationFilter: string[];
44
+ fileWatcher: string[];
45
+ };
46
+ resolveConfig?(config: Config, ctx: LanguageServiceContext): void;
47
+ onInitialize?(_: vscode.InitializeResult, env: RuntimeEnvironment): void;
48
+ onInitialized?(getLanguageService: (uri: string) => Promise<LanguageService | undefined>, env: RuntimeEnvironment): void;
42
49
  };
43
- resolveConfig?(config: Config, ctx: LanguageServiceContext): void;
44
- onInitialize?(_: vscode.InitializeResult): void;
45
- onInitialized?(getLanguageService: (uri: string) => Promise<C>): void;
46
- };
50
+ }
47
51
  export declare enum ServerMode {
48
52
  Semantic = 0,
49
53
  Syntactic = 2
@@ -55,7 +59,23 @@ export declare enum DiagnosticModel {
55
59
  }
56
60
  export interface LanguageServerInitializationOptions {
57
61
  typescript?: {
62
+ /**
63
+ * Absolute path to node_modules/typescript/lib
64
+ */
58
65
  tsdk: string;
66
+ /**
67
+ * Dependencies versions.
68
+ * @example
69
+ * {
70
+ * '@vue/compiler-sfc': '3.0.0',
71
+ * 'typescript': '4.0.0',
72
+ * }
73
+ */
74
+ versions?: Record<string, string>;
75
+ /**
76
+ * CDN url for dependencies.
77
+ */
78
+ cdn?: string;
59
79
  };
60
80
  l10n?: {
61
81
  location: string;
@@ -63,6 +83,12 @@ export interface LanguageServerInitializationOptions {
63
83
  serverMode?: ServerMode;
64
84
  diagnosticModel?: DiagnosticModel;
65
85
  textDocumentSync?: vscode.TextDocumentSyncKind | number;
86
+ /**
87
+ * For better JSON parsing performance language server will filter CompletionList.
88
+ *
89
+ * Enable this option if you want to get complete CompletionList in language client.
90
+ */
91
+ fullCompletionList?: boolean;
66
92
  ignoreTriggerCharacters?: string[];
67
93
  /**
68
94
  * https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29#cancellation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-server",
3
- "version": "1.2.0-alpha.9",
3
+ "version": "1.3.0-alpha.1",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -17,17 +17,17 @@
17
17
  "directory": "packages/language-server"
18
18
  },
19
19
  "dependencies": {
20
- "@volar/language-core": "1.2.0-alpha.9",
21
- "@volar/language-service": "1.2.0-alpha.9",
22
- "@volar/shared": "1.2.0-alpha.9",
23
- "@vscode/l10n": "^0.0.10",
24
- "request-light": "^0.6.0",
20
+ "@volar/language-core": "1.3.0-alpha.1",
21
+ "@volar/language-service": "1.3.0-alpha.1",
22
+ "@volar/shared": "1.3.0-alpha.1",
23
+ "@vscode/l10n": "^0.0.11",
24
+ "request-light": "^0.7.0",
25
25
  "typesafe-path": "^0.2.2",
26
- "vscode-html-languageservice": "^5.0.3",
27
- "vscode-languageserver": "^8.0.2",
28
- "vscode-languageserver-protocol": "^3.17.2",
26
+ "vscode-html-languageservice": "^5.0.4",
27
+ "vscode-languageserver": "^8.1.0",
28
+ "vscode-languageserver-protocol": "^3.17.3",
29
29
  "vscode-languageserver-textdocument": "^1.0.8",
30
30
  "vscode-uri": "^3.0.7"
31
31
  },
32
- "gitHead": "ac8ebe9dd13bb6881769afb8612d3a9489ba7799"
32
+ "gitHead": "2926dc4af31890e01f6218773e88578ddf0de658"
33
33
  }