@volar/kit 1.2.0-alpha.5 → 1.2.0-alpha.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/kit",
3
- "version": "1.2.0-alpha.5",
3
+ "version": "1.2.0-alpha.6",
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.2.0-alpha.5",
17
- "@volar/shared": "1.2.0-alpha.5",
16
+ "@volar/language-service": "1.2.0-alpha.6",
17
+ "@volar/shared": "1.2.0-alpha.6",
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": "a31d022987c454762d1ba3c9ef8e7d74a5bca06a"
24
+ "gitHead": "a3eb3ce03430eddb58be999bf7799d01cefbf787"
25
25
  }
package/out/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { DiagnosticSeverity, FormattingOptions, Config } from '@volar/language-service';
2
- import type * as ts from 'typescript/lib/tsserverlibrary';
3
- export declare function create(tsConfigPath: string, config: Config, extraFileExtensions?: ts.FileExtensionInfo[], ts?: typeof import('typescript/lib/tsserverlibrary')): {
4
- roots: string[];
5
- lint: (fileName: string, severity?: DiagnosticSeverity, throwLevel?: DiagnosticSeverity) => Promise<(crossFileFix?: boolean) => Promise<void>>;
6
- format: (fileName: string, options: FormattingOptions) => Promise<void>;
7
- };
package/out/index.js DELETED
@@ -1,130 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.create = void 0;
12
- const language_service_1 = require("@volar/language-service");
13
- const shared_1 = require("@volar/shared");
14
- const fs = require("fs");
15
- const path = require("path");
16
- const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
17
- const vscode_uri_1 = require("vscode-uri");
18
- function create(tsConfigPath, config, extraFileExtensions = [], ts = require('typescript')) {
19
- let projectVersion = 0;
20
- const scriptVersions = new Map();
21
- const scriptSnapshots = new Map();
22
- const jsonConfig = ts.readJsonConfigFile(tsConfigPath, ts.sys.readFile);
23
- const parsedCommandLine = ts.parseJsonSourceFileConfigFileContent(jsonConfig, ts.sys, path.dirname(tsConfigPath), {}, tsConfigPath, undefined, extraFileExtensions);
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) => {
25
- if (!scriptSnapshots.has(fileName)) {
26
- const fileText = ts.sys.readFile(fileName);
27
- if (fileText !== undefined) {
28
- scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(fileText));
29
- }
30
- }
31
- return scriptSnapshots.get(fileName);
32
- }, getTypeScriptModule: () => ts });
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
38
- },
39
- },
40
- });
41
- const formatHost = {
42
- getCurrentDirectory: () => host.getCurrentDirectory(),
43
- getCanonicalFileName: (fileName) => { var _a; return ((_a = host.useCaseSensitiveFileNames) === null || _a === void 0 ? void 0 : _a.call(host)) ? fileName : fileName.toLowerCase(); },
44
- getNewLine: () => { var _a, _b; return (_b = (_a = host.getNewLine) === null || _a === void 0 ? void 0 : _a.call(host)) !== null && _b !== void 0 ? _b : '\n'; },
45
- };
46
- return {
47
- roots: parsedCommandLine.fileNames,
48
- lint,
49
- format,
50
- };
51
- function lint(fileName, severity = language_service_1.DiagnosticSeverity.Hint, throwLevel = 0) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const uri = (0, shared_1.fileNameToUri)(fileName);
54
- const document = service.context.getTextDocument(uri);
55
- let diagnostics = [];
56
- if (document) {
57
- diagnostics = yield service.doValidation(uri);
58
- diagnostics = diagnostics.filter(diagnostic => { var _a; return ((_a = diagnostic.severity) !== null && _a !== void 0 ? _a : 1) <= severity; });
59
- const errors = diagnostics.map(diagnostic => ({
60
- category: diagnostic.severity === language_service_1.DiagnosticSeverity.Error ? ts.DiagnosticCategory.Error : ts.DiagnosticCategory.Warning,
61
- code: diagnostic.code,
62
- file: ts.createSourceFile(fileName, document.getText(), ts.ScriptTarget.JSON),
63
- start: document.offsetAt(diagnostic.range.start),
64
- length: document.offsetAt(diagnostic.range.end) - document.offsetAt(diagnostic.range.start),
65
- messageText: diagnostic.message,
66
- }));
67
- const text = ts.formatDiagnosticsWithColorAndContext(errors, formatHost);
68
- if (text) {
69
- if (diagnostics.some(diagnostic => { var _a; return ((_a = diagnostic.severity) !== null && _a !== void 0 ? _a : 1) <= throwLevel; })) {
70
- throw text;
71
- }
72
- else {
73
- console.log(text);
74
- }
75
- }
76
- }
77
- return (crossFileFix = false) => __awaiter(this, void 0, void 0, function* () {
78
- var _a;
79
- const document = service.context.getTextDocument(uri);
80
- if (document) {
81
- const range = { start: document.positionAt(0), end: document.positionAt(document.getText().length) };
82
- const codeActions = yield service.doCodeActions(uri, range, { diagnostics, only: ['source.fixAll'], triggerKind: language_service_1.CodeActionTriggerKind.Invoked });
83
- if (codeActions) {
84
- for (let i = 0; i < codeActions.length; i++) {
85
- codeActions[i] = yield service.doCodeActionResolve(codeActions[i]);
86
- }
87
- const edits = codeActions.map(codeAction => codeAction.edit).filter((edit) => !!edit);
88
- if (edits.length) {
89
- const rootEdit = edits[0];
90
- (0, language_service_1.mergeWorkspaceEdits)(rootEdit, ...edits.slice(1));
91
- for (const uri in (_a = rootEdit.changes) !== null && _a !== void 0 ? _a : {}) {
92
- if (uri === document.uri || crossFileFix) {
93
- const edits = rootEdit.changes[uri];
94
- if (edits.length) {
95
- const editDocument = service.context.getTextDocument(uri);
96
- if (editDocument) {
97
- const newString = vscode_languageserver_textdocument_1.TextDocument.applyEdits(editDocument, edits);
98
- writeFile((0, shared_1.uriToFileName)(uri), newString);
99
- }
100
- }
101
- }
102
- }
103
- if (crossFileFix) {
104
- // TODO: rootEdit.documentChanges
105
- }
106
- }
107
- }
108
- }
109
- });
110
- });
111
- }
112
- function format(fileName, options) {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- const uri = (0, shared_1.fileNameToUri)(fileName);
115
- const document = service.context.getTextDocument(uri);
116
- if (document) {
117
- const edits = yield service.format(uri, options);
118
- if (edits === null || edits === void 0 ? void 0 : edits.length) {
119
- const newString = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
120
- writeFile(fileName, newString);
121
- }
122
- }
123
- });
124
- }
125
- }
126
- exports.create = create;
127
- function writeFile(fileName, newText) {
128
- fs.writeFileSync(fileName, newText, { encoding: 'utf8' });
129
- }
130
- //# sourceMappingURL=index.js.map