@volar/kit 1.11.1 → 2.0.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.
- package/index.d.ts +1 -3
- package/index.js +1 -2
- package/lib/createChecker.d.ts +22 -0
- package/lib/createChecker.js +232 -0
- package/lib/createFormatter.d.ts +4 -6
- package/lib/createFormatter.js +17 -68
- package/lib/createServiceEnvironment.d.ts +2 -0
- package/lib/createServiceEnvironment.js +96 -0
- package/lib/utils.d.ts +2 -5
- package/lib/utils.js +2 -78
- package/package.json +4 -3
- package/lib/createLinter.d.ts +0 -9
- package/lib/createLinter.js +0 -110
- package/lib/createProject.d.ts +0 -17
- package/lib/createProject.js +0 -94
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -16,6 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("@volar/language-service"), exports);
|
|
18
18
|
__exportStar(require("./lib/createFormatter"), exports);
|
|
19
|
-
__exportStar(require("./lib/
|
|
20
|
-
__exportStar(require("./lib/createProject"), exports);
|
|
19
|
+
__exportStar(require("./lib/createChecker"), exports);
|
|
21
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Diagnostic, LanguagePlugin, ServicePlugin, TypeScriptProjectHost } from '@volar/language-service';
|
|
2
|
+
import * as ts from 'typescript';
|
|
3
|
+
export declare function createTypeScriptChecker(languages: LanguagePlugin[], services: ServicePlugin[], tsconfig: string, extraFileExtensions?: ts.FileExtensionInfo[]): {
|
|
4
|
+
check: (fileName: string) => Promise<Diagnostic[]>;
|
|
5
|
+
fixErrors: (fileName: string, diagnostics: Diagnostic[], only: string[] | undefined, writeFile: (fileName: string, newText: string) => Promise<void>) => Promise<void>;
|
|
6
|
+
printErrors: (fileName: string, diagnostics: Diagnostic[], rootPath?: string) => string;
|
|
7
|
+
languageHost: TypeScriptProjectHost;
|
|
8
|
+
settings: {};
|
|
9
|
+
fileCreated(fileName: string): void;
|
|
10
|
+
fileUpdated(fileName: string): void;
|
|
11
|
+
fileDeleted(fileName: string): void;
|
|
12
|
+
};
|
|
13
|
+
export declare function createTypeScriptInferredChecker(languages: LanguagePlugin[], services: ServicePlugin[], getScriptFileNames: () => string[], compilerOptions?: ts.CompilerOptions): {
|
|
14
|
+
check: (fileName: string) => Promise<Diagnostic[]>;
|
|
15
|
+
fixErrors: (fileName: string, diagnostics: Diagnostic[], only: string[] | undefined, writeFile: (fileName: string, newText: string) => Promise<void>) => Promise<void>;
|
|
16
|
+
printErrors: (fileName: string, diagnostics: Diagnostic[], rootPath?: string) => string;
|
|
17
|
+
languageHost: TypeScriptProjectHost;
|
|
18
|
+
settings: {};
|
|
19
|
+
fileCreated(fileName: string): void;
|
|
20
|
+
fileUpdated(fileName: string): void;
|
|
21
|
+
fileDeleted(fileName: string): void;
|
|
22
|
+
};
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTypeScriptInferredChecker = exports.createTypeScriptChecker = void 0;
|
|
4
|
+
const language_service_1 = require("@volar/language-service");
|
|
5
|
+
const path = require("typesafe-path/posix");
|
|
6
|
+
const ts = require("typescript");
|
|
7
|
+
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
8
|
+
const createServiceEnvironment_1 = require("./createServiceEnvironment");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const typescript_1 = require("@volar/typescript");
|
|
11
|
+
function createTypeScriptChecker(languages, services, tsconfig, extraFileExtensions = []) {
|
|
12
|
+
const tsconfigPath = (0, utils_1.asPosix)(tsconfig);
|
|
13
|
+
return createTypeScriptCheckerWorker(languages, services, tsconfigPath, env => {
|
|
14
|
+
return createTypeScriptLanguageHost(env, () => {
|
|
15
|
+
const parsed = ts.parseJsonSourceFileConfigFileContent(ts.readJsonConfigFile(tsconfigPath, ts.sys.readFile), ts.sys, path.dirname(tsconfigPath), undefined, tsconfigPath, undefined, extraFileExtensions);
|
|
16
|
+
parsed.fileNames = parsed.fileNames.map(utils_1.asPosix);
|
|
17
|
+
return parsed;
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
exports.createTypeScriptChecker = createTypeScriptChecker;
|
|
22
|
+
function createTypeScriptInferredChecker(languages, services, getScriptFileNames, compilerOptions = utils_1.defaultCompilerOptions) {
|
|
23
|
+
return createTypeScriptCheckerWorker(languages, services, undefined, env => {
|
|
24
|
+
return createTypeScriptLanguageHost(env, () => ({
|
|
25
|
+
options: compilerOptions,
|
|
26
|
+
fileNames: getScriptFileNames().map(utils_1.asPosix),
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
exports.createTypeScriptInferredChecker = createTypeScriptInferredChecker;
|
|
31
|
+
function createTypeScriptCheckerWorker(languages, services, configFileName, getProjectHost) {
|
|
32
|
+
let settings = {};
|
|
33
|
+
const env = (0, createServiceEnvironment_1.createServiceEnvironment)(() => settings);
|
|
34
|
+
const didChangeWatchedFilesCallbacks = new Set();
|
|
35
|
+
env.onDidChangeWatchedFiles = (cb) => {
|
|
36
|
+
didChangeWatchedFilesCallbacks.add(cb);
|
|
37
|
+
return {
|
|
38
|
+
dispose: () => {
|
|
39
|
+
didChangeWatchedFilesCallbacks.delete(cb);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const languageHost = getProjectHost(env);
|
|
44
|
+
const language = (0, typescript_1.createLanguage)(ts, ts.sys, languages, configFileName, languageHost);
|
|
45
|
+
const service = (0, language_service_1.createLanguageService)(language, services, env);
|
|
46
|
+
return {
|
|
47
|
+
// apis
|
|
48
|
+
check,
|
|
49
|
+
fixErrors,
|
|
50
|
+
printErrors,
|
|
51
|
+
languageHost,
|
|
52
|
+
// settings
|
|
53
|
+
get settings() {
|
|
54
|
+
return settings;
|
|
55
|
+
},
|
|
56
|
+
set settings(v) {
|
|
57
|
+
settings = v;
|
|
58
|
+
},
|
|
59
|
+
// file events
|
|
60
|
+
fileCreated(fileName) {
|
|
61
|
+
fileEvent(fileName, 1);
|
|
62
|
+
},
|
|
63
|
+
fileUpdated(fileName) {
|
|
64
|
+
fileEvent(fileName, 2);
|
|
65
|
+
},
|
|
66
|
+
fileDeleted(fileName) {
|
|
67
|
+
fileEvent(fileName, 3);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
function fileEvent(fileName, type) {
|
|
71
|
+
fileName = (0, utils_1.asPosix)(fileName);
|
|
72
|
+
for (const cb of didChangeWatchedFilesCallbacks) {
|
|
73
|
+
cb({ changes: [{ uri: (0, utils_1.fileNameToUri)(fileName), type }] });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function check(fileName) {
|
|
77
|
+
fileName = (0, utils_1.asPosix)(fileName);
|
|
78
|
+
const uri = (0, utils_1.fileNameToUri)(fileName);
|
|
79
|
+
return service.doValidation(uri, 'all');
|
|
80
|
+
}
|
|
81
|
+
async function fixErrors(fileName, diagnostics, only, writeFile) {
|
|
82
|
+
fileName = (0, utils_1.asPosix)(fileName);
|
|
83
|
+
const uri = (0, utils_1.fileNameToUri)(fileName);
|
|
84
|
+
const sourceFile = service.context.language.files.getSourceFile(uri);
|
|
85
|
+
if (sourceFile) {
|
|
86
|
+
const document = service.context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
87
|
+
const range = { start: document.positionAt(0), end: document.positionAt(document.getText().length) };
|
|
88
|
+
const codeActions = await service.doCodeActions(uri, range, { diagnostics, only, triggerKind: 1 });
|
|
89
|
+
if (codeActions) {
|
|
90
|
+
for (let i = 0; i < codeActions.length; i++) {
|
|
91
|
+
codeActions[i] = await service.doCodeActionResolve(codeActions[i]);
|
|
92
|
+
}
|
|
93
|
+
const edits = codeActions.map(codeAction => codeAction.edit).filter((edit) => !!edit);
|
|
94
|
+
if (edits.length) {
|
|
95
|
+
const rootEdit = edits[0];
|
|
96
|
+
(0, language_service_1.mergeWorkspaceEdits)(rootEdit, ...edits.slice(1));
|
|
97
|
+
for (const uri in rootEdit.changes ?? {}) {
|
|
98
|
+
const edits = rootEdit.changes[uri];
|
|
99
|
+
if (edits.length) {
|
|
100
|
+
const editFile = service.context.language.files.getSourceFile(uri);
|
|
101
|
+
if (editFile) {
|
|
102
|
+
const editDocument = service.context.documents.get(uri, editFile.languageId, editFile.snapshot);
|
|
103
|
+
const newString = vscode_languageserver_textdocument_1.TextDocument.applyEdits(editDocument, edits);
|
|
104
|
+
await writeFile((0, utils_1.uriToFileName)(uri), newString);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
for (const change of rootEdit.documentChanges ?? []) {
|
|
109
|
+
if ('textDocument' in change) {
|
|
110
|
+
const editFile = service.context.language.files.getSourceFile(change.textDocument.uri);
|
|
111
|
+
if (editFile) {
|
|
112
|
+
const editDocument = service.context.documents.get(change.textDocument.uri, editFile.languageId, editFile.snapshot);
|
|
113
|
+
const newString = vscode_languageserver_textdocument_1.TextDocument.applyEdits(editDocument, change.edits);
|
|
114
|
+
await writeFile((0, utils_1.uriToFileName)(change.textDocument.uri), newString);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// TODO: CreateFile | RenameFile | DeleteFile
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function printErrors(fileName, diagnostics, rootPath = process.cwd()) {
|
|
124
|
+
let text = formatErrors(fileName, diagnostics, rootPath);
|
|
125
|
+
for (const diagnostic of diagnostics) {
|
|
126
|
+
text = text.replace(`TS${diagnostic.code}`, (diagnostic.source ?? '') + (diagnostic.code ? `(${diagnostic.code})` : ''));
|
|
127
|
+
}
|
|
128
|
+
return text;
|
|
129
|
+
}
|
|
130
|
+
function formatErrors(fileName, diagnostics, rootPath) {
|
|
131
|
+
fileName = (0, utils_1.asPosix)(fileName);
|
|
132
|
+
const uri = (0, utils_1.fileNameToUri)(fileName);
|
|
133
|
+
const sourceFile = service.context.language.files.getSourceFile(uri);
|
|
134
|
+
const document = service.context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
135
|
+
const errors = diagnostics.map(diagnostic => ({
|
|
136
|
+
category: diagnostic.severity === 1 ? ts.DiagnosticCategory.Error : ts.DiagnosticCategory.Warning,
|
|
137
|
+
code: diagnostic.code,
|
|
138
|
+
file: ts.createSourceFile(fileName, document.getText(), ts.ScriptTarget.JSON),
|
|
139
|
+
start: document.offsetAt(diagnostic.range.start),
|
|
140
|
+
length: document.offsetAt(diagnostic.range.end) - document.offsetAt(diagnostic.range.start),
|
|
141
|
+
messageText: diagnostic.message,
|
|
142
|
+
}));
|
|
143
|
+
const text = ts.formatDiagnosticsWithColorAndContext(errors, {
|
|
144
|
+
getCurrentDirectory: () => rootPath,
|
|
145
|
+
getCanonicalFileName: (fileName) => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
|
|
146
|
+
getNewLine: () => ts.sys.newLine,
|
|
147
|
+
});
|
|
148
|
+
return text;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function createTypeScriptLanguageHost(env, createParsedCommandLine) {
|
|
152
|
+
let scriptSnapshotsCache = new Map();
|
|
153
|
+
let parsedCommandLine = createParsedCommandLine();
|
|
154
|
+
let projectVersion = 0;
|
|
155
|
+
let shouldCheckRootFiles = false;
|
|
156
|
+
const host = {
|
|
157
|
+
getCurrentDirectory: () => {
|
|
158
|
+
return env.uriToFileName(env.workspaceFolder.uri.toString());
|
|
159
|
+
},
|
|
160
|
+
getCompilationSettings: () => {
|
|
161
|
+
return parsedCommandLine.options;
|
|
162
|
+
},
|
|
163
|
+
getProjectVersion: () => {
|
|
164
|
+
checkRootFilesUpdate();
|
|
165
|
+
return projectVersion.toString();
|
|
166
|
+
},
|
|
167
|
+
getScriptFileNames: () => {
|
|
168
|
+
checkRootFilesUpdate();
|
|
169
|
+
return parsedCommandLine.fileNames;
|
|
170
|
+
},
|
|
171
|
+
getScriptSnapshot: (fileName) => {
|
|
172
|
+
if (!scriptSnapshotsCache.has(fileName)) {
|
|
173
|
+
const fileText = ts.sys.readFile(fileName, 'utf8');
|
|
174
|
+
if (fileText !== undefined) {
|
|
175
|
+
scriptSnapshotsCache.set(fileName, ts.ScriptSnapshot.fromString(fileText));
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
scriptSnapshotsCache.set(fileName, undefined);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return scriptSnapshotsCache.get(fileName);
|
|
182
|
+
},
|
|
183
|
+
getFileName: env.uriToFileName,
|
|
184
|
+
getFileId: env.fileNameToUri,
|
|
185
|
+
getLanguageId: language_service_1.resolveCommonLanguageId,
|
|
186
|
+
};
|
|
187
|
+
env.onDidChangeWatchedFiles?.(({ changes }) => {
|
|
188
|
+
for (const change of changes) {
|
|
189
|
+
const fileName = env.uriToFileName(change.uri);
|
|
190
|
+
if (change.type === 2) {
|
|
191
|
+
if (scriptSnapshotsCache.has(fileName)) {
|
|
192
|
+
projectVersion++;
|
|
193
|
+
scriptSnapshotsCache.delete(fileName);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else if (change.type === 3) {
|
|
197
|
+
if (scriptSnapshotsCache.has(fileName)) {
|
|
198
|
+
projectVersion++;
|
|
199
|
+
scriptSnapshotsCache.delete(fileName);
|
|
200
|
+
parsedCommandLine.fileNames = parsedCommandLine.fileNames.filter(name => name !== fileName);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else if (change.type === 1) {
|
|
204
|
+
shouldCheckRootFiles = true;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
return host;
|
|
209
|
+
function checkRootFilesUpdate() {
|
|
210
|
+
if (!shouldCheckRootFiles)
|
|
211
|
+
return;
|
|
212
|
+
shouldCheckRootFiles = false;
|
|
213
|
+
const newParsedCommandLine = createParsedCommandLine();
|
|
214
|
+
if (!arrayItemsEqual(newParsedCommandLine.fileNames, parsedCommandLine.fileNames)) {
|
|
215
|
+
parsedCommandLine.fileNames = newParsedCommandLine.fileNames;
|
|
216
|
+
projectVersion++;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function arrayItemsEqual(a, b) {
|
|
221
|
+
if (a.length !== b.length) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
const set = new Set(a);
|
|
225
|
+
for (const file of b) {
|
|
226
|
+
if (!set.has(file)) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=createChecker.js.map
|
package/lib/createFormatter.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function createFormatter(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
settings: any;
|
|
1
|
+
import { FormattingOptions, LanguagePlugin, ServicePlugin } from '@volar/language-service';
|
|
2
|
+
export declare function createFormatter(languages: LanguagePlugin[], services: ServicePlugin[]): {
|
|
3
|
+
format: (content: string, languageId: string, options: FormattingOptions) => Promise<string>;
|
|
4
|
+
settings: {};
|
|
6
5
|
};
|
|
7
|
-
//# sourceMappingURL=createFormatter.d.ts.map
|
package/lib/createFormatter.js
CHANGED
|
@@ -2,88 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createFormatter = void 0;
|
|
4
4
|
const language_service_1 = require("@volar/language-service");
|
|
5
|
+
const ts = require("typescript");
|
|
5
6
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const ts = require('typescript');
|
|
7
|
+
const createServiceEnvironment_1 = require("./createServiceEnvironment");
|
|
8
|
+
function createFormatter(languages, services) {
|
|
9
|
+
let fakeUri = 'file:///dummy.txt';
|
|
10
10
|
let settings = {};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let fakeScriptLanguageId;
|
|
15
|
-
const service = (0, language_service_1.createLanguageService)({ typescript: ts }, {
|
|
16
|
-
workspaceUri: vscode_uri_1.URI.file('/'),
|
|
17
|
-
rootUri: vscode_uri_1.URI.file('/'),
|
|
18
|
-
uriToFileName: uri => {
|
|
19
|
-
if (uri.startsWith(dummyScriptUri))
|
|
20
|
-
return uri.replace(dummyScriptUri, fakeScriptFileName);
|
|
21
|
-
return (0, utils_1.uriToFileName)(uri);
|
|
22
|
-
},
|
|
23
|
-
fileNameToUri: fileName => {
|
|
24
|
-
if (fileName.startsWith(fakeScriptFileName))
|
|
25
|
-
return fileName.replace(fakeScriptFileName, dummyScriptUri);
|
|
26
|
-
return (0, utils_1.fileNameToUri)(fileName);
|
|
27
|
-
},
|
|
28
|
-
getConfiguration: section => (0, utils_1.getConfiguration)(settings, section),
|
|
29
|
-
fs: utils_1.fs,
|
|
30
|
-
console,
|
|
31
|
-
}, config, createHost());
|
|
11
|
+
const env = (0, createServiceEnvironment_1.createServiceEnvironment)(() => settings);
|
|
12
|
+
const files = (0, language_service_1.createFileProvider)(languages, false, () => { });
|
|
13
|
+
const service = (0, language_service_1.createLanguageService)({ files }, services, env);
|
|
32
14
|
return {
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
// apis
|
|
16
|
+
format,
|
|
17
|
+
// settings
|
|
35
18
|
get settings() {
|
|
36
19
|
return settings;
|
|
37
20
|
},
|
|
38
|
-
set settings(
|
|
39
|
-
settings =
|
|
21
|
+
set settings(v) {
|
|
22
|
+
settings = v;
|
|
40
23
|
},
|
|
41
24
|
};
|
|
42
|
-
async function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const document = service.context.
|
|
46
|
-
|
|
47
|
-
throw `file not found: ${fileName}`;
|
|
48
|
-
const edits = await service.format(uri, options, undefined, undefined);
|
|
49
|
-
if (edits?.length) {
|
|
50
|
-
const newString = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
|
51
|
-
return newString;
|
|
52
|
-
}
|
|
53
|
-
return document.getText();
|
|
54
|
-
}
|
|
55
|
-
async function formatCode(content, languageId, options) {
|
|
56
|
-
fakeScriptSnapshot = ts.ScriptSnapshot.fromString(content);
|
|
57
|
-
fakeScriptLanguageId = languageId;
|
|
58
|
-
const document = service.context.getTextDocument(dummyScriptUri);
|
|
59
|
-
const edits = await service.format(dummyScriptUri, options, undefined, undefined);
|
|
25
|
+
async function format(content, languageId, options) {
|
|
26
|
+
const snapshot = ts.ScriptSnapshot.fromString(content);
|
|
27
|
+
files.updateSourceFile(fakeUri, languageId, snapshot);
|
|
28
|
+
const document = service.context.documents.get(fakeUri, languageId, snapshot);
|
|
29
|
+
const edits = await service.format(fakeUri, options, undefined, undefined);
|
|
60
30
|
if (edits?.length) {
|
|
61
31
|
const newString = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
|
62
32
|
return newString;
|
|
63
33
|
}
|
|
64
34
|
return content;
|
|
65
35
|
}
|
|
66
|
-
function createHost() {
|
|
67
|
-
let projectVersion = 0;
|
|
68
|
-
const host = {
|
|
69
|
-
workspacePath: '/',
|
|
70
|
-
rootPath: '/',
|
|
71
|
-
getCompilationSettings: () => compilerOptions,
|
|
72
|
-
getProjectVersion: () => (projectVersion++).toString(),
|
|
73
|
-
getScriptFileNames: () => fakeScriptSnapshot ? [fakeScriptFileName] : [],
|
|
74
|
-
getScriptSnapshot: (fileName) => {
|
|
75
|
-
if (fileName === fakeScriptFileName) {
|
|
76
|
-
return fakeScriptSnapshot;
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
getLanguageId: fileName => {
|
|
80
|
-
if (fileName === fakeScriptFileName) {
|
|
81
|
-
return fakeScriptLanguageId;
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
return host;
|
|
86
|
-
}
|
|
87
36
|
}
|
|
88
37
|
exports.createFormatter = createFormatter;
|
|
89
38
|
//# sourceMappingURL=createFormatter.js.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createServiceEnvironment = void 0;
|
|
4
|
+
const language_service_1 = require("@volar/language-service");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
function createServiceEnvironment(getSettings) {
|
|
9
|
+
return {
|
|
10
|
+
workspaceFolder: {
|
|
11
|
+
uri: vscode_uri_1.URI.file(process.cwd()),
|
|
12
|
+
name: '',
|
|
13
|
+
},
|
|
14
|
+
uriToFileName: utils_1.uriToFileName,
|
|
15
|
+
fileNameToUri: utils_1.fileNameToUri,
|
|
16
|
+
getConfiguration(section) {
|
|
17
|
+
const settings = getSettings();
|
|
18
|
+
if (section in settings) {
|
|
19
|
+
return settings[section];
|
|
20
|
+
}
|
|
21
|
+
let result;
|
|
22
|
+
for (const settingKey in settings) {
|
|
23
|
+
if (settingKey.startsWith(`${section}.`)) {
|
|
24
|
+
const value = settings[settingKey];
|
|
25
|
+
const props = settingKey.substring(section.length + 1).split('.');
|
|
26
|
+
result ??= {};
|
|
27
|
+
let current = result;
|
|
28
|
+
while (props.length > 1) {
|
|
29
|
+
const prop = props.shift();
|
|
30
|
+
if (typeof current[prop] !== 'object') {
|
|
31
|
+
current[prop] = {};
|
|
32
|
+
}
|
|
33
|
+
current = current[prop];
|
|
34
|
+
}
|
|
35
|
+
current[props.shift()] = value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
},
|
|
40
|
+
fs: nodeFs,
|
|
41
|
+
console,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.createServiceEnvironment = createServiceEnvironment;
|
|
45
|
+
const nodeFs = {
|
|
46
|
+
stat(uri) {
|
|
47
|
+
if (uri.startsWith('file://')) {
|
|
48
|
+
try {
|
|
49
|
+
const stats = fs.statSync((0, utils_1.uriToFileName)(uri), { throwIfNoEntry: false });
|
|
50
|
+
if (stats) {
|
|
51
|
+
return {
|
|
52
|
+
type: stats.isFile() ? language_service_1.FileType.File
|
|
53
|
+
: stats.isDirectory() ? language_service_1.FileType.Directory
|
|
54
|
+
: stats.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
|
|
55
|
+
: language_service_1.FileType.Unknown,
|
|
56
|
+
ctime: stats.ctimeMs,
|
|
57
|
+
mtime: stats.mtimeMs,
|
|
58
|
+
size: stats.size,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
readFile(uri, encoding) {
|
|
68
|
+
if (uri.startsWith('file://')) {
|
|
69
|
+
try {
|
|
70
|
+
return fs.readFileSync((0, utils_1.uriToFileName)(uri), { encoding: encoding ?? 'utf-8' });
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
readDirectory(uri) {
|
|
78
|
+
if (uri.startsWith('file://')) {
|
|
79
|
+
try {
|
|
80
|
+
const dirName = (0, utils_1.uriToFileName)(uri);
|
|
81
|
+
const files = fs.readdirSync(dirName, { withFileTypes: true });
|
|
82
|
+
return files.map(file => {
|
|
83
|
+
return [file.name, file.isFile() ? language_service_1.FileType.File
|
|
84
|
+
: file.isDirectory() ? language_service_1.FileType.Directory
|
|
85
|
+
: file.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
|
|
86
|
+
: language_service_1.FileType.Unknown];
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return [];
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=createServiceEnvironment.js.map
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="typesafe-path" />
|
|
2
|
+
import type * as path from 'typesafe-path/posix';
|
|
2
3
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
-
import { FileSystem } from '@volar/language-service';
|
|
4
4
|
export declare const defaultCompilerOptions: ts.CompilerOptions;
|
|
5
5
|
export declare function asPosix(path: string): path.PosixPath;
|
|
6
6
|
export declare const uriToFileName: (uri: string) => string;
|
|
7
7
|
export declare const fileNameToUri: (fileName: string) => string;
|
|
8
|
-
export declare function getConfiguration(settings: any, section: string): any;
|
|
9
|
-
export declare const fs: FileSystem;
|
|
10
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.fileNameToUri = exports.uriToFileName = exports.asPosix = exports.defaultCompilerOptions = void 0;
|
|
4
4
|
const vscode_uri_1 = require("vscode-uri");
|
|
5
|
-
|
|
6
|
-
const _fs = require("fs");
|
|
5
|
+
require("fs");
|
|
7
6
|
exports.defaultCompilerOptions = {
|
|
8
7
|
allowJs: true,
|
|
9
8
|
allowSyntheticDefaultImports: true,
|
|
@@ -19,79 +18,4 @@ const uriToFileName = (uri) => vscode_uri_1.URI.parse(uri).fsPath.replace(/\\/g,
|
|
|
19
18
|
exports.uriToFileName = uriToFileName;
|
|
20
19
|
const fileNameToUri = (fileName) => vscode_uri_1.URI.file(fileName).toString();
|
|
21
20
|
exports.fileNameToUri = fileNameToUri;
|
|
22
|
-
function getConfiguration(settings, section) {
|
|
23
|
-
if (section in settings) {
|
|
24
|
-
return settings[section];
|
|
25
|
-
}
|
|
26
|
-
let result;
|
|
27
|
-
for (const settingKey in settings) {
|
|
28
|
-
if (settingKey.startsWith(`${section}.`)) {
|
|
29
|
-
const value = settings[settingKey];
|
|
30
|
-
const props = settingKey.substring(section.length + 1).split('.');
|
|
31
|
-
result ??= {};
|
|
32
|
-
let current = result;
|
|
33
|
-
while (props.length > 1) {
|
|
34
|
-
const prop = props.shift();
|
|
35
|
-
if (typeof current[prop] !== 'object') {
|
|
36
|
-
current[prop] = {};
|
|
37
|
-
}
|
|
38
|
-
current = current[prop];
|
|
39
|
-
}
|
|
40
|
-
current[props.shift()] = value;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
exports.getConfiguration = getConfiguration;
|
|
46
|
-
exports.fs = {
|
|
47
|
-
stat(uri) {
|
|
48
|
-
if (uri.startsWith('file://')) {
|
|
49
|
-
try {
|
|
50
|
-
const stats = _fs.statSync((0, exports.uriToFileName)(uri), { throwIfNoEntry: false });
|
|
51
|
-
if (stats) {
|
|
52
|
-
return {
|
|
53
|
-
type: stats.isFile() ? language_service_1.FileType.File
|
|
54
|
-
: stats.isDirectory() ? language_service_1.FileType.Directory
|
|
55
|
-
: stats.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
|
|
56
|
-
: language_service_1.FileType.Unknown,
|
|
57
|
-
ctime: stats.ctimeMs,
|
|
58
|
-
mtime: stats.mtimeMs,
|
|
59
|
-
size: stats.size,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
readFile(uri, encoding) {
|
|
69
|
-
if (uri.startsWith('file://')) {
|
|
70
|
-
try {
|
|
71
|
-
return _fs.readFileSync((0, exports.uriToFileName)(uri), { encoding: encoding ?? 'utf-8' });
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
readDirectory(uri) {
|
|
79
|
-
if (uri.startsWith('file://')) {
|
|
80
|
-
try {
|
|
81
|
-
const dirName = (0, exports.uriToFileName)(uri);
|
|
82
|
-
const files = _fs.readdirSync(dirName, { withFileTypes: true });
|
|
83
|
-
return files.map(file => {
|
|
84
|
-
return [file.name, file.isFile() ? language_service_1.FileType.File
|
|
85
|
-
: file.isDirectory() ? language_service_1.FileType.Directory
|
|
86
|
-
: file.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
|
|
87
|
-
: language_service_1.FileType.Unknown];
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
catch {
|
|
91
|
-
return [];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return [];
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
21
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/kit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"directory": "packages/kit"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/language-service": "
|
|
15
|
+
"@volar/language-service": "2.0.0-alpha.1",
|
|
16
|
+
"@volar/typescript": "2.0.0-alpha.1",
|
|
16
17
|
"typesafe-path": "^0.2.2",
|
|
17
18
|
"vscode-languageserver-textdocument": "^1.0.11",
|
|
18
19
|
"vscode-uri": "^3.0.8"
|
|
@@ -23,5 +24,5 @@
|
|
|
23
24
|
"peerDependencies": {
|
|
24
25
|
"typescript": "*"
|
|
25
26
|
},
|
|
26
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "3af80b55081397c58cc5c0b6ed44d1810aa0dea1"
|
|
27
28
|
}
|
package/lib/createLinter.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Config, Diagnostic, TypeScriptLanguageHost } from '@volar/language-service';
|
|
2
|
-
export declare function createLinter(config: Config, host: TypeScriptLanguageHost): {
|
|
3
|
-
check: (fileName: string) => Promise<Diagnostic[]>;
|
|
4
|
-
fixErrors: (fileName: string, diagnostics: Diagnostic[], only: string[] | undefined, writeFile: (fileName: string, newText: string) => Promise<void>) => Promise<void>;
|
|
5
|
-
printErrors: (fileName: string, diagnostics: Diagnostic[], rootPath?: string) => string;
|
|
6
|
-
logErrors: (fileName: string, diagnostics: Diagnostic[], rootPath?: string) => void;
|
|
7
|
-
settings: any;
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=createLinter.d.ts.map
|
package/lib/createLinter.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createLinter = void 0;
|
|
4
|
-
const language_service_1 = require("@volar/language-service");
|
|
5
|
-
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
const vscode_uri_1 = require("vscode-uri");
|
|
8
|
-
function createLinter(config, host) {
|
|
9
|
-
let settings = {};
|
|
10
|
-
const ts = require('typescript');
|
|
11
|
-
const service = (0, language_service_1.createLanguageService)({ typescript: ts }, {
|
|
12
|
-
uriToFileName: utils_1.uriToFileName,
|
|
13
|
-
fileNameToUri: utils_1.fileNameToUri,
|
|
14
|
-
workspaceUri: vscode_uri_1.URI.parse((0, utils_1.fileNameToUri)(host.workspacePath)),
|
|
15
|
-
rootUri: vscode_uri_1.URI.parse((0, utils_1.fileNameToUri)(host.rootPath)),
|
|
16
|
-
getConfiguration: section => (0, utils_1.getConfiguration)(settings, section),
|
|
17
|
-
fs: utils_1.fs,
|
|
18
|
-
console,
|
|
19
|
-
}, config, host);
|
|
20
|
-
return {
|
|
21
|
-
check,
|
|
22
|
-
fixErrors,
|
|
23
|
-
printErrors,
|
|
24
|
-
logErrors,
|
|
25
|
-
get settings() {
|
|
26
|
-
return settings;
|
|
27
|
-
},
|
|
28
|
-
set settings(newValue) {
|
|
29
|
-
settings = newValue;
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
function check(fileName) {
|
|
33
|
-
fileName = (0, utils_1.asPosix)(fileName);
|
|
34
|
-
const uri = (0, utils_1.fileNameToUri)(fileName);
|
|
35
|
-
return service.doValidation(uri, 'all');
|
|
36
|
-
}
|
|
37
|
-
async function fixErrors(fileName, diagnostics, only, writeFile) {
|
|
38
|
-
fileName = (0, utils_1.asPosix)(fileName);
|
|
39
|
-
const uri = (0, utils_1.fileNameToUri)(fileName);
|
|
40
|
-
const document = service.context.getTextDocument(uri);
|
|
41
|
-
if (document) {
|
|
42
|
-
const range = { start: document.positionAt(0), end: document.positionAt(document.getText().length) };
|
|
43
|
-
const codeActions = await service.doCodeActions(uri, range, { diagnostics, only, triggerKind: 1 });
|
|
44
|
-
if (codeActions) {
|
|
45
|
-
for (let i = 0; i < codeActions.length; i++) {
|
|
46
|
-
codeActions[i] = await service.doCodeActionResolve(codeActions[i]);
|
|
47
|
-
}
|
|
48
|
-
const edits = codeActions.map(codeAction => codeAction.edit).filter((edit) => !!edit);
|
|
49
|
-
if (edits.length) {
|
|
50
|
-
const rootEdit = edits[0];
|
|
51
|
-
(0, language_service_1.mergeWorkspaceEdits)(rootEdit, ...edits.slice(1));
|
|
52
|
-
for (const uri in rootEdit.changes ?? {}) {
|
|
53
|
-
const edits = rootEdit.changes[uri];
|
|
54
|
-
if (edits.length) {
|
|
55
|
-
const editDocument = service.context.getTextDocument(uri);
|
|
56
|
-
if (editDocument) {
|
|
57
|
-
const newString = vscode_languageserver_textdocument_1.TextDocument.applyEdits(editDocument, edits);
|
|
58
|
-
await writeFile((0, utils_1.uriToFileName)(uri), newString);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
for (const change of rootEdit.documentChanges ?? []) {
|
|
63
|
-
if ('textDocument' in change) {
|
|
64
|
-
const editDocument = service.context.getTextDocument(change.textDocument.uri);
|
|
65
|
-
if (editDocument) {
|
|
66
|
-
const newString = vscode_languageserver_textdocument_1.TextDocument.applyEdits(editDocument, change.edits);
|
|
67
|
-
await writeFile((0, utils_1.uriToFileName)(change.textDocument.uri), newString);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// TODO: CreateFile | RenameFile | DeleteFile
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function printErrors(fileName, diagnostics, rootPath = process.cwd()) {
|
|
77
|
-
let text = formatErrors(fileName, diagnostics, rootPath);
|
|
78
|
-
for (const diagnostic of diagnostics) {
|
|
79
|
-
text = text.replace(`TS${diagnostic.code}`, (diagnostic.source ?? '') + (diagnostic.code ? `(${diagnostic.code})` : ''));
|
|
80
|
-
}
|
|
81
|
-
return text;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* @deprecated please use `printErrors()` instead of
|
|
85
|
-
*/
|
|
86
|
-
function logErrors(fileName, diagnostics, rootPath = process.cwd()) {
|
|
87
|
-
console.log(printErrors(fileName, diagnostics, rootPath));
|
|
88
|
-
}
|
|
89
|
-
function formatErrors(fileName, diagnostics, rootPath) {
|
|
90
|
-
fileName = (0, utils_1.asPosix)(fileName);
|
|
91
|
-
const uri = (0, utils_1.fileNameToUri)(fileName);
|
|
92
|
-
const document = service.context.getTextDocument(uri);
|
|
93
|
-
const errors = diagnostics.map(diagnostic => ({
|
|
94
|
-
category: diagnostic.severity === 1 ? ts.DiagnosticCategory.Error : ts.DiagnosticCategory.Warning,
|
|
95
|
-
code: diagnostic.code,
|
|
96
|
-
file: ts.createSourceFile(fileName, document.getText(), ts.ScriptTarget.JSON),
|
|
97
|
-
start: document.offsetAt(diagnostic.range.start),
|
|
98
|
-
length: document.offsetAt(diagnostic.range.end) - document.offsetAt(diagnostic.range.start),
|
|
99
|
-
messageText: diagnostic.message,
|
|
100
|
-
}));
|
|
101
|
-
const text = ts.formatDiagnosticsWithColorAndContext(errors, {
|
|
102
|
-
getCurrentDirectory: () => rootPath,
|
|
103
|
-
getCanonicalFileName: (fileName) => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
|
|
104
|
-
getNewLine: () => ts.sys.newLine,
|
|
105
|
-
});
|
|
106
|
-
return text;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
exports.createLinter = createLinter;
|
|
110
|
-
//# sourceMappingURL=createLinter.js.map
|
package/lib/createProject.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { TypeScriptLanguageHost } from '@volar/language-service';
|
|
2
|
-
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
-
export declare function createInferredProject(rootPath: string, getScriptFileNames: () => string[], compilerOptions?: ts.CompilerOptions): {
|
|
4
|
-
languageHost: TypeScriptLanguageHost;
|
|
5
|
-
fileUpdated(fileName: string): void;
|
|
6
|
-
fileDeleted(fileName: string): void;
|
|
7
|
-
fileCreated(fileName: string): void;
|
|
8
|
-
reload(): void;
|
|
9
|
-
};
|
|
10
|
-
export declare function createProject(sourceTsconfigPath: string, extraFileExtensions?: ts.FileExtensionInfo[], existingOptions?: ts.CompilerOptions): {
|
|
11
|
-
languageHost: TypeScriptLanguageHost;
|
|
12
|
-
fileUpdated(fileName: string): void;
|
|
13
|
-
fileDeleted(fileName: string): void;
|
|
14
|
-
fileCreated(fileName: string): void;
|
|
15
|
-
reload(): void;
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=createProject.d.ts.map
|
package/lib/createProject.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createProject = exports.createInferredProject = void 0;
|
|
4
|
-
const path = require("typesafe-path/posix");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
function createInferredProject(rootPath, getScriptFileNames, compilerOptions = utils_1.defaultCompilerOptions) {
|
|
7
|
-
return createProjectBase(rootPath, () => ({
|
|
8
|
-
options: compilerOptions,
|
|
9
|
-
fileNames: getScriptFileNames().map(utils_1.asPosix),
|
|
10
|
-
}));
|
|
11
|
-
}
|
|
12
|
-
exports.createInferredProject = createInferredProject;
|
|
13
|
-
function createProject(sourceTsconfigPath, extraFileExtensions = [], existingOptions) {
|
|
14
|
-
const ts = require('typescript');
|
|
15
|
-
const tsconfigPath = (0, utils_1.asPosix)(sourceTsconfigPath);
|
|
16
|
-
return createProjectBase(path.dirname(tsconfigPath), () => {
|
|
17
|
-
const parsed = ts.parseJsonSourceFileConfigFileContent(ts.readJsonConfigFile(tsconfigPath, ts.sys.readFile), ts.sys, path.dirname(tsconfigPath), existingOptions, tsconfigPath, undefined, extraFileExtensions);
|
|
18
|
-
parsed.fileNames = parsed.fileNames.map(utils_1.asPosix);
|
|
19
|
-
return parsed;
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
exports.createProject = createProject;
|
|
23
|
-
function createProjectBase(rootPath, createParsedCommandLine) {
|
|
24
|
-
const ts = require('typescript');
|
|
25
|
-
const languageHost = {
|
|
26
|
-
workspacePath: rootPath,
|
|
27
|
-
rootPath: rootPath,
|
|
28
|
-
getCompilationSettings: () => {
|
|
29
|
-
return parsedCommandLine.options;
|
|
30
|
-
},
|
|
31
|
-
getProjectVersion: () => {
|
|
32
|
-
checkRootFilesUpdate();
|
|
33
|
-
return projectVersion.toString();
|
|
34
|
-
},
|
|
35
|
-
getScriptFileNames: () => {
|
|
36
|
-
checkRootFilesUpdate();
|
|
37
|
-
return parsedCommandLine.fileNames;
|
|
38
|
-
},
|
|
39
|
-
getScriptSnapshot: (fileName) => {
|
|
40
|
-
if (!scriptSnapshotsCache.has(fileName)) {
|
|
41
|
-
const fileText = ts.sys.readFile(fileName, 'utf8');
|
|
42
|
-
if (fileText !== undefined) {
|
|
43
|
-
scriptSnapshotsCache.set(fileName, ts.ScriptSnapshot.fromString(fileText));
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
scriptSnapshotsCache.set(fileName, undefined);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return scriptSnapshotsCache.get(fileName);
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
let scriptSnapshotsCache = new Map();
|
|
53
|
-
let parsedCommandLine = createParsedCommandLine();
|
|
54
|
-
let projectVersion = 0;
|
|
55
|
-
let shouldCheckRootFiles = false;
|
|
56
|
-
return {
|
|
57
|
-
languageHost,
|
|
58
|
-
fileUpdated(fileName) {
|
|
59
|
-
fileName = (0, utils_1.asPosix)(fileName);
|
|
60
|
-
if (scriptSnapshotsCache.has(fileName)) {
|
|
61
|
-
projectVersion++;
|
|
62
|
-
scriptSnapshotsCache.delete(fileName);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
fileDeleted(fileName) {
|
|
66
|
-
fileName = (0, utils_1.asPosix)(fileName);
|
|
67
|
-
if (scriptSnapshotsCache.has(fileName)) {
|
|
68
|
-
projectVersion++;
|
|
69
|
-
scriptSnapshotsCache.delete(fileName);
|
|
70
|
-
parsedCommandLine.fileNames = parsedCommandLine.fileNames.filter(name => name !== fileName);
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
fileCreated(fileName) {
|
|
74
|
-
fileName = (0, utils_1.asPosix)(fileName);
|
|
75
|
-
shouldCheckRootFiles = true;
|
|
76
|
-
},
|
|
77
|
-
reload() {
|
|
78
|
-
scriptSnapshotsCache.clear();
|
|
79
|
-
projectVersion++;
|
|
80
|
-
parsedCommandLine = createParsedCommandLine();
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
function checkRootFilesUpdate() {
|
|
84
|
-
if (!shouldCheckRootFiles)
|
|
85
|
-
return;
|
|
86
|
-
shouldCheckRootFiles = false;
|
|
87
|
-
const newParsedCommandLine = createParsedCommandLine();
|
|
88
|
-
if (newParsedCommandLine.fileNames.length !== parsedCommandLine.fileNames.length) {
|
|
89
|
-
parsedCommandLine.fileNames = newParsedCommandLine.fileNames;
|
|
90
|
-
projectVersion++;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
//# sourceMappingURL=createProject.js.map
|