@volar/kit 1.1.0-alpha.2 → 1.2.0-alpha.10

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.
package/out/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { FormattingOptions, LanguageModule, LanguageServicePlugin, DiagnosticSeverity } from '@volar/language-service';
1
+ import { DiagnosticSeverity, FormattingOptions, Config } from '@volar/language-service';
2
2
  import type * as ts from 'typescript/lib/tsserverlibrary';
3
- export declare function create(tsConfigPath: string, plugins: LanguageServicePlugin[], extraFileExtensions?: ts.FileExtensionInfo[], languageModules?: LanguageModule[], ts?: typeof import('typescript/lib/tsserverlibrary')): {
3
+ export declare function create(tsConfigPath: string, config: Config, extraFileExtensions?: ts.FileExtensionInfo[], ts?: typeof import('typescript/lib/tsserverlibrary')): {
4
4
  roots: string[];
5
5
  lint: (fileName: string, severity?: DiagnosticSeverity, throwLevel?: DiagnosticSeverity) => Promise<(crossFileFix?: boolean) => Promise<void>>;
6
6
  format: (fileName: string, options: FormattingOptions) => Promise<void>;
package/out/index.js CHANGED
@@ -15,11 +15,10 @@ const fs = require("fs");
15
15
  const path = require("path");
16
16
  const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
17
17
  const vscode_uri_1 = require("vscode-uri");
18
- function create(tsConfigPath, plugins, extraFileExtensions = [], languageModules = [], ts = require('typescript')) {
18
+ function create(tsConfigPath, config, extraFileExtensions = [], ts = require('typescript')) {
19
19
  let projectVersion = 0;
20
20
  const scriptVersions = new Map();
21
21
  const scriptSnapshots = new Map();
22
- const textDocuments = new Map();
23
22
  const jsonConfig = ts.readJsonConfigFile(tsConfigPath, ts.sys.readFile);
24
23
  const parsedCommandLine = ts.parseJsonSourceFileConfigFileContent(jsonConfig, ts.sys, path.dirname(tsConfigPath), {}, tsConfigPath, undefined, extraFileExtensions);
25
24
  const host = Object.assign(Object.assign({}, ts.sys), { getProjectVersion: () => projectVersion.toString(), getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options), useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames, getCompilationSettings: () => parsedCommandLine.options, getScriptFileNames: () => parsedCommandLine.fileNames, getProjectReferences: () => parsedCommandLine.projectReferences, getScriptVersion: (fileName) => { var _a, _b; return (_b = (_a = scriptVersions.get(fileName)) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''; }, getScriptSnapshot: (fileName) => {
@@ -31,41 +30,14 @@ function create(tsConfigPath, plugins, extraFileExtensions = [], languageModules
31
30
  }
32
31
  return scriptSnapshots.get(fileName);
33
32
  }, getTypeScriptModule: () => ts });
34
- const core = (0, language_service_1.createLanguageContext)(host, languageModules);
35
- const ctx = {
36
- typescript: {
37
- module: ts,
38
- languageServiceHost: core.typescript.languageServiceHost,
39
- languageService: ts.createLanguageService(core.typescript.languageServiceHost),
40
- },
41
- env: {
42
- rootUri: vscode_uri_1.URI.file(path.dirname(tsConfigPath)),
43
- documentContext: {
44
- resolveReference() {
45
- return undefined; // TODO
46
- },
33
+ const service = (0, language_service_1.createLanguageService)(host, config, {
34
+ rootUri: vscode_uri_1.URI.file(path.dirname(tsConfigPath)),
35
+ documentContext: {
36
+ resolveReference() {
37
+ return undefined; // TODO
47
38
  },
48
39
  },
49
- host,
50
- core,
51
- documents: (0, language_service_1.createDocumentsAndSourceMaps)(core.virtualFiles),
52
- get plugins() {
53
- return plugins.map(plugin => plugin(ctx, service));
54
- },
55
- getTextDocument(uri) {
56
- if (!textDocuments.has(uri)) {
57
- const snapshot = host.getScriptSnapshot((0, shared_1.uriToFileName)(uri));
58
- if (snapshot) {
59
- textDocuments.set(uri, vscode_languageserver_textdocument_1.TextDocument.create(uri, (0, shared_1.syntaxToLanguageId)(uri.substring(uri.lastIndexOf('.') + 1)), 0, snapshot.getText(0, snapshot.getLength())));
60
- }
61
- else {
62
- textDocuments.set(uri, undefined);
63
- }
64
- }
65
- return textDocuments.get(uri);
66
- },
67
- };
68
- const service = (0, language_service_1.createLanguageService)(ctx);
40
+ });
69
41
  const formatHost = {
70
42
  getCurrentDirectory: () => host.getCurrentDirectory(),
71
43
  getCanonicalFileName: (fileName) => { var _a; return ((_a = host.useCaseSensitiveFileNames) === null || _a === void 0 ? void 0 : _a.call(host)) ? fileName : fileName.toLowerCase(); },
@@ -79,7 +51,7 @@ function create(tsConfigPath, plugins, extraFileExtensions = [], languageModules
79
51
  function lint(fileName, severity = language_service_1.DiagnosticSeverity.Hint, throwLevel = 0) {
80
52
  return __awaiter(this, void 0, void 0, function* () {
81
53
  const uri = (0, shared_1.fileNameToUri)(fileName);
82
- const document = ctx.getTextDocument(uri);
54
+ const document = service.context.getTextDocument(uri);
83
55
  let diagnostics = [];
84
56
  if (document) {
85
57
  diagnostics = yield service.doValidation(uri);
@@ -104,7 +76,7 @@ function create(tsConfigPath, plugins, extraFileExtensions = [], languageModules
104
76
  }
105
77
  return (crossFileFix = false) => __awaiter(this, void 0, void 0, function* () {
106
78
  var _a;
107
- const document = ctx.getTextDocument(uri);
79
+ const document = service.context.getTextDocument(uri);
108
80
  if (document) {
109
81
  const range = { start: document.positionAt(0), end: document.positionAt(document.getText().length) };
110
82
  const codeActions = yield service.doCodeActions(uri, range, { diagnostics, only: ['source.fixAll'], triggerKind: language_service_1.CodeActionTriggerKind.Invoked });
@@ -120,7 +92,7 @@ function create(tsConfigPath, plugins, extraFileExtensions = [], languageModules
120
92
  if (uri === document.uri || crossFileFix) {
121
93
  const edits = rootEdit.changes[uri];
122
94
  if (edits.length) {
123
- const editDocument = ctx.getTextDocument(uri);
95
+ const editDocument = service.context.getTextDocument(uri);
124
96
  if (editDocument) {
125
97
  const newString = vscode_languageserver_textdocument_1.TextDocument.applyEdits(editDocument, edits);
126
98
  writeFile((0, shared_1.uriToFileName)(uri), newString);
@@ -140,7 +112,7 @@ function create(tsConfigPath, plugins, extraFileExtensions = [], languageModules
140
112
  function format(fileName, options) {
141
113
  return __awaiter(this, void 0, void 0, function* () {
142
114
  const uri = (0, shared_1.fileNameToUri)(fileName);
143
- const document = ctx.getTextDocument(uri);
115
+ const document = service.context.getTextDocument(uri);
144
116
  if (document) {
145
117
  const edits = yield service.format(uri, options);
146
118
  if (edits === null || edits === void 0 ? void 0 : edits.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/kit",
3
- "version": "1.1.0-alpha.2",
3
+ "version": "1.2.0-alpha.10",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -13,13 +13,13 @@
13
13
  "directory": "packages/kit"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/language-service": "1.1.0-alpha.2",
17
- "@volar/shared": "1.1.0-alpha.2",
16
+ "@volar/language-service": "1.2.0-alpha.10",
17
+ "@volar/shared": "1.2.0-alpha.10",
18
18
  "vscode-languageserver-textdocument": "^1.0.8",
19
19
  "vscode-uri": "^3.0.7"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "typescript": "*"
23
23
  },
24
- "gitHead": "2a5ff13854187a26c1b5e36c5eab8b94cbd08375"
24
+ "gitHead": "c0b7580b14966d28d7c6df5da9baa41111f9f8d9"
25
25
  }