@volar/language-server 1.1.0-alpha.2 → 1.2.0-alpha.2

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,16 +1,16 @@
1
1
  import * as embedded from '@volar/language-core';
2
2
  import * as embeddedLS from '@volar/language-service';
3
+ import { LanguageServiceConfig } from '@volar/language-service';
3
4
  import * as path from 'typesafe-path';
4
5
  import type * as ts from 'typescript/lib/tsserverlibrary';
5
6
  import { URI } from 'vscode-uri';
6
7
  import { WorkspaceContext } from './workspace';
7
- import { ServerConfig } from './utils/serverConfig';
8
8
  export interface ProjectContext {
9
9
  workspace: WorkspaceContext;
10
10
  rootUri: URI;
11
11
  tsConfig: path.PosixPath | ts.CompilerOptions;
12
12
  documentRegistry: ts.DocumentRegistry | undefined;
13
- serverConfig: ServerConfig | undefined;
13
+ serverConfig: LanguageServiceConfig | undefined;
14
14
  }
15
15
  export type Project = ReturnType<typeof createProject>;
16
16
  export declare function createProject(context: ProjectContext): Promise<{
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.createProject = void 0;
12
- const embedded = require("@volar/language-core");
13
12
  const embeddedLS = require("@volar/language-service");
14
13
  const shared = require("@volar/shared");
15
14
  const path = require("typesafe-path");
@@ -63,37 +62,37 @@ function createProject(context) {
63
62
  dispose,
64
63
  };
65
64
  function getLanguageService() {
65
+ var _a, _b, _c, _d, _e, _f;
66
66
  if (!languageService) {
67
- 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();
68
- const languageContext = embedded.createLanguageContext(languageServiceHost, languageModules);
69
- const languageServiceContext = embeddedLS.createLanguageServiceContext({
67
+ const config = {
68
+ languages: Object.assign({}, (_b = (_a = context.serverConfig) === null || _a === void 0 ? void 0 : _a.languages) !== null && _b !== void 0 ? _b : {}),
69
+ plugins: Object.assign({}, (_d = (_c = context.serverConfig) === null || _c === void 0 ? void 0 : _c.plugins) !== null && _d !== void 0 ? _d : {}),
70
+ rules: Object.assign({}, (_e = context.serverConfig) === null || _e === void 0 ? void 0 : _e.rules),
71
+ };
72
+ const env = {
73
+ rootUri: context.rootUri,
74
+ configurationHost: context.workspace.workspaces.configurationHost,
75
+ fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
76
+ documentContext: getDocumentContext(context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
77
+ schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
78
+ const protocol = uri.substring(0, uri.indexOf(':'));
79
+ const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
80
+ if (builtInHandler) {
81
+ return yield builtInHandler(uri);
82
+ }
83
+ return '';
84
+ }),
85
+ };
86
+ const lsCtx = {
87
+ project: context,
88
+ env,
89
+ sys,
70
90
  host: languageServiceHost,
71
- context: languageContext,
72
- getPlugins() {
73
- var _a, _b;
74
- return [
75
- ...(_b = (_a = context.serverConfig) === null || _a === void 0 ? void 0 : _a.plugins) !== null && _b !== void 0 ? _b : [],
76
- ...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(),
77
- ];
78
- },
79
- env: {
80
- rootUri: context.rootUri,
81
- configurationHost: context.workspace.workspaces.configurationHost,
82
- fileSystemProvider: context.workspace.workspaces.server.runtimeEnv.fileSystemProvide,
83
- documentContext: getDocumentContext(context.workspace.workspaces.ts, languageServiceHost, context.rootUri.toString()),
84
- schemaRequestService: (uri) => __awaiter(this, void 0, void 0, function* () {
85
- const protocol = uri.substring(0, uri.indexOf(':'));
86
- const builtInHandler = context.workspace.workspaces.server.runtimeEnv.schemaRequestHandlers[protocol];
87
- if (builtInHandler) {
88
- return yield builtInHandler(uri);
89
- }
90
- return '';
91
- }),
92
- },
93
- documentRegistry: context.documentRegistry,
94
- getLanguageService: () => languageService,
95
- });
96
- languageService = embeddedLS.createLanguageService(languageServiceContext);
91
+ };
92
+ for (const plugin of context.workspace.workspaces.plugins) {
93
+ (_f = plugin.resolveConfig) === null || _f === void 0 ? void 0 : _f.call(plugin, config, lsCtx);
94
+ }
95
+ languageService = embeddedLS.createLanguageService(languageServiceHost, config, env, context.documentRegistry);
97
96
  }
98
97
  return languageService;
99
98
  }
@@ -184,11 +183,6 @@ function createProject(context) {
184
183
  if (context.workspace.workspaces.tsLocalized) {
185
184
  host.getLocalizedDiagnosticMessages = () => context.workspace.workspaces.tsLocalized;
186
185
  }
187
- for (const plugin of context.workspace.workspaces.plugins) {
188
- if (context.workspace.workspaces.ts && plugin.resolveLanguageServiceHost) {
189
- host = plugin.resolveLanguageServiceHost(context.workspace.workspaces.ts, sys, context.tsConfig, host);
190
- }
191
- }
192
186
  return host;
193
187
  function getScriptVersion(fileName) {
194
188
  var _a, _b;
@@ -1,5 +1,2 @@
1
- import { LanguageServicePlugin } from '@volar/language-service';
2
- export interface ServerConfig {
3
- plugins?: LanguageServicePlugin[];
4
- }
5
- export declare function loadServerConfig(dir: string, configFile: string | undefined): ServerConfig | undefined;
1
+ import { LanguageServiceConfig } from "@volar/language-service";
2
+ export declare function loadConfig(dir: string, configFile: string | undefined): LanguageServiceConfig | undefined;
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, "__esModule", { value: true });
2
- exports.loadServerConfig = void 0;
3
- function loadServerConfig(dir, configFile) {
2
+ exports.loadConfig = void 0;
3
+ function loadConfig(dir, configFile) {
4
4
  let configPath;
5
5
  try {
6
6
  configPath = require.resolve(configFile !== null && configFile !== void 0 ? configFile : './volar.config.js', { paths: [dir] });
@@ -17,5 +17,5 @@ function loadServerConfig(dir, configFile) {
17
17
  console.log(err);
18
18
  }
19
19
  }
20
- exports.loadServerConfig = loadServerConfig;
20
+ exports.loadConfig = loadConfig;
21
21
  //# sourceMappingURL=serverConfig.js.map
@@ -23,7 +23,7 @@ function createWorkspace(context) {
23
23
  var _a, _b, _c;
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  let inferredProject;
26
- const serverConfig = (0, serverConfig_1.loadServerConfig)(shared.uriToFileName(context.rootUri.toString()), context.workspaces.initOptions.configFilePath);
26
+ const serverConfig = (0, serverConfig_1.loadConfig)(shared.uriToFileName(context.rootUri.toString()), context.workspaces.initOptions.configFilePath);
27
27
  const sys = (_a = context.workspaces.fileSystemHost) === null || _a === void 0 ? void 0 : _a.getWorkspaceFileSystem(context.rootUri);
28
28
  const documentRegistry = sys ? (_b = context.workspaces.ts) === null || _b === void 0 ? void 0 : _b.createDocumentRegistry(sys.useCaseSensitiveFileNames, shared.uriToFileName(context.rootUri.toString())) : undefined;
29
29
  const projects = (0, uriMap_1.createUriMap)();
@@ -1,4 +1,4 @@
1
- /// <reference types="typesafe-path" />
1
+ /// <reference types="node_modules/.pnpm/typesafe-path@0.2.2/node_modules/typesafe-path" />
2
2
  import { ConfigurationHost } from '@volar/language-service';
3
3
  import type * as ts from 'typescript/lib/tsserverlibrary';
4
4
  import * as vscode from 'vscode-languageserver';
package/out/types.d.ts CHANGED
@@ -5,7 +5,8 @@ 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 { LanguageServiceRuntimeContext } from '@volar/language-service';
8
+ import { LanguageServiceConfig, LanguageServiceRuntimeContext } from '@volar/language-service';
9
+ import { ProjectContext } from './common/project';
9
10
  export type FileSystemHost = {
10
11
  ready(connection: vscode.Connection): void;
11
12
  reload(): void;
@@ -26,16 +27,20 @@ export interface RuntimeEnvironment {
26
27
  setImmediate(callback: (...args: any[]) => void, ...args: any[]): vscode.Disposable;
27
28
  };
28
29
  }
29
- export type LanguageServerPlugin<A extends LanguageServerInitializationOptions = LanguageServerInitializationOptions, B extends embedded.LanguageServiceHost = embedded.LanguageServiceHost, C = embeddedLS.LanguageService> = (initOptions: A) => {
30
+ export interface LanguageServiceContext {
31
+ project: ProjectContext;
32
+ env: LanguageServiceRuntimeContext['env'];
33
+ host: embedded.LanguageServiceHost;
34
+ sys: FileSystem;
35
+ }
36
+ export type LanguageServerPlugin<A extends LanguageServerInitializationOptions = LanguageServerInitializationOptions, C = embeddedLS.LanguageService> = (initOptions: A) => {
30
37
  tsconfigExtraFileExtensions: ts.FileExtensionInfo[];
31
38
  diagnosticDocumentSelector: vscode.DocumentSelector;
32
39
  extensions: {
33
40
  fileRenameOperationFilter: string[];
34
41
  fileWatcher: string[];
35
42
  };
36
- resolveLanguageServiceHost?(ts: typeof import('typescript/lib/tsserverlibrary'), sys: FileSystem, tsConfig: string | ts.CompilerOptions, host: embedded.LanguageServiceHost): B;
37
- getLanguageModules?(host: B): embedded.LanguageModule[];
38
- getLanguageServicePlugins?(host: B, context: LanguageServiceRuntimeContext): embeddedLS.LanguageServicePlugin[];
43
+ resolveConfig?(config: LanguageServiceConfig, ctx: LanguageServiceContext): void;
39
44
  onInitialize?(_: vscode.InitializeResult): void;
40
45
  onInitialized?(getLanguageService: (uri: string) => Promise<C>): void;
41
46
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-server",
3
- "version": "1.1.0-alpha.2",
3
+ "version": "1.2.0-alpha.2",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -17,9 +17,9 @@
17
17
  "directory": "packages/language-server"
18
18
  },
19
19
  "dependencies": {
20
- "@volar/language-core": "1.1.0-alpha.2",
21
- "@volar/language-service": "1.1.0-alpha.2",
22
- "@volar/shared": "1.1.0-alpha.2",
20
+ "@volar/language-core": "1.2.0-alpha.2",
21
+ "@volar/language-service": "1.2.0-alpha.2",
22
+ "@volar/shared": "1.2.0-alpha.2",
23
23
  "@vscode/l10n": "^0.0.10",
24
24
  "request-light": "^0.6.0",
25
25
  "typesafe-path": "^0.2.2",
@@ -29,5 +29,5 @@
29
29
  "vscode-languageserver-textdocument": "^1.0.8",
30
30
  "vscode-uri": "^3.0.7"
31
31
  },
32
- "gitHead": "2a5ff13854187a26c1b5e36c5eab8b94cbd08375"
32
+ "gitHead": "cc4da3728cbbc0933c9957c298d0a36090fbedc1"
33
33
  }