@volar/kit 1.6.9-patch.2 → 1.7.0
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/README.md +3 -6
- package/out/createFormatter.d.ts +1 -2
- package/out/createFormatter.js +23 -32
- package/out/createLinter.d.ts +2 -2
- package/out/createLinter.js +6 -5
- package/out/createProject.d.ts +3 -5
- package/out/createProject.js +27 -47
- package/out/utils.d.ts +2 -0
- package/out/utils.js +37 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -31,11 +31,11 @@ createWatcher(path.dirname(tsconfig), ['ts', 'js', 'foo'])
|
|
|
31
31
|
})
|
|
32
32
|
.on('unlink', (fileName) => {
|
|
33
33
|
project.fileDeleted(fileName);
|
|
34
|
-
update(
|
|
34
|
+
update();
|
|
35
35
|
})
|
|
36
36
|
.on('change', (fileName) => {
|
|
37
37
|
project.fileUpdated(fileName);
|
|
38
|
-
update(
|
|
38
|
+
update();
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
function createWatcher(rootPath: string, extension: string[]) {
|
|
@@ -45,10 +45,7 @@ function createWatcher(rootPath: string, extension: string[]) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
async function update(
|
|
49
|
-
|
|
50
|
-
if (fileNameCheckRelated && !project.isKnownRelatedFile(fileNameCheckRelated))
|
|
51
|
-
return;
|
|
48
|
+
async function update() {
|
|
52
49
|
|
|
53
50
|
const currentReq = ++req;
|
|
54
51
|
const isCanceled = () => currentReq !== req;
|
package/out/createFormatter.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Config, FormattingOptions } from '@volar/language-service';
|
|
2
|
-
|
|
3
|
-
export declare function createFormatter(config: Config, compilerOptions?: ts.CompilerOptions): {
|
|
2
|
+
export declare function createFormatter(config: Config, compilerOptions?: import("typescript/lib/tsserverlibrary").CompilerOptions): {
|
|
4
3
|
formatFile: (fileName: string, options: FormattingOptions) => Promise<string>;
|
|
5
4
|
formatCode: (content: string, languageId: string, options: FormattingOptions) => Promise<string>;
|
|
6
5
|
settings: any;
|
package/out/createFormatter.js
CHANGED
|
@@ -9,23 +9,24 @@ function createFormatter(config, compilerOptions = utils_1.defaultCompilerOption
|
|
|
9
9
|
const ts = require('typescript');
|
|
10
10
|
let settings = {};
|
|
11
11
|
let dummyScriptUri = 'file:///dummy.txt';
|
|
12
|
-
let
|
|
13
|
-
let
|
|
14
|
-
let
|
|
15
|
-
let
|
|
12
|
+
let fakeScriptVersion = 0;
|
|
13
|
+
let fakeScriptFileName = '/dummy.txt';
|
|
14
|
+
let fakeScriptSnapshot = ts.ScriptSnapshot.fromString('');
|
|
15
|
+
let fakeScriptLanguageId;
|
|
16
16
|
const service = (0, language_service_1.createLanguageService)({ typescript: ts }, {
|
|
17
17
|
rootUri: vscode_uri_1.URI.file('/'),
|
|
18
18
|
uriToFileName: uri => {
|
|
19
19
|
if (uri.startsWith(dummyScriptUri))
|
|
20
|
-
return uri.replace(dummyScriptUri,
|
|
20
|
+
return uri.replace(dummyScriptUri, fakeScriptFileName);
|
|
21
21
|
return (0, utils_1.uriToFileName)(uri);
|
|
22
22
|
},
|
|
23
23
|
fileNameToUri: fileName => {
|
|
24
|
-
if (fileName.startsWith(
|
|
25
|
-
return fileName.replace(
|
|
24
|
+
if (fileName.startsWith(fakeScriptFileName))
|
|
25
|
+
return fileName.replace(fakeScriptFileName, dummyScriptUri);
|
|
26
26
|
return (0, utils_1.fileNameToUri)(fileName);
|
|
27
27
|
},
|
|
28
28
|
getConfiguration: section => (0, utils_1.getConfiguration)(settings, section),
|
|
29
|
+
fs: utils_1.fs,
|
|
29
30
|
}, config, createHost());
|
|
30
31
|
return {
|
|
31
32
|
formatFile,
|
|
@@ -51,9 +52,9 @@ function createFormatter(config, compilerOptions = utils_1.defaultCompilerOption
|
|
|
51
52
|
return document.getText();
|
|
52
53
|
}
|
|
53
54
|
async function formatCode(content, languageId, options) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
fakeScriptSnapshot = ts.ScriptSnapshot.fromString(content);
|
|
56
|
+
fakeScriptVersion++;
|
|
57
|
+
fakeScriptLanguageId = languageId;
|
|
57
58
|
const document = service.context.getTextDocument(dummyScriptUri);
|
|
58
59
|
const edits = await service.format(dummyScriptUri, options, undefined, undefined);
|
|
59
60
|
if (edits?.length) {
|
|
@@ -63,36 +64,26 @@ function createFormatter(config, compilerOptions = utils_1.defaultCompilerOption
|
|
|
63
64
|
return content;
|
|
64
65
|
}
|
|
65
66
|
function createHost() {
|
|
66
|
-
|
|
67
|
-
const scriptSnapshots = new Map();
|
|
67
|
+
let projectVersion = 0;
|
|
68
68
|
const host = {
|
|
69
|
-
|
|
69
|
+
getCurrentDirectory: () => '/',
|
|
70
70
|
getCompilationSettings: () => compilerOptions,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
useCaseSensitiveFileNames: () => ts.sys.useCaseSensitiveFileNames,
|
|
71
|
+
getProjectVersion: () => projectVersion++,
|
|
72
|
+
getScriptFileNames: () => fakeScriptSnapshot ? [fakeScriptFileName] : [],
|
|
74
73
|
getScriptVersion: (fileName) => {
|
|
75
|
-
if (fileName ===
|
|
76
|
-
return
|
|
74
|
+
if (fileName === fakeScriptFileName) {
|
|
75
|
+
return fakeScriptVersion.toString();
|
|
77
76
|
}
|
|
78
|
-
return scriptVersions.get(fileName)?.toString() ?? '';
|
|
79
77
|
},
|
|
80
78
|
getScriptSnapshot: (fileName) => {
|
|
81
|
-
if (fileName ===
|
|
82
|
-
return
|
|
79
|
+
if (fileName === fakeScriptFileName) {
|
|
80
|
+
return fakeScriptSnapshot;
|
|
83
81
|
}
|
|
84
|
-
if (!scriptSnapshots.has(fileName)) {
|
|
85
|
-
const fileText = ts.sys.readFile(fileName);
|
|
86
|
-
if (fileText !== undefined) {
|
|
87
|
-
scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(fileText));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return scriptSnapshots.get(fileName);
|
|
91
82
|
},
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
return
|
|
95
|
-
|
|
83
|
+
getLanguageId: fileName => {
|
|
84
|
+
if (fileName === fakeScriptFileName) {
|
|
85
|
+
return fakeScriptLanguageId;
|
|
86
|
+
}
|
|
96
87
|
},
|
|
97
88
|
};
|
|
98
89
|
return host;
|
package/out/createLinter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Config, Diagnostic,
|
|
2
|
-
export declare function createLinter(config: Config, host:
|
|
1
|
+
import { Config, Diagnostic, TypeScriptLanguageHost } from '@volar/language-service';
|
|
2
|
+
export declare function createLinter(config: Config, host: TypeScriptLanguageHost): {
|
|
3
3
|
check: (fileName: string) => Promise<Diagnostic[]>;
|
|
4
4
|
fixErrors: (fileName: string, diagnostics: Diagnostic[], only: string[] | undefined, writeFile: (fileName: string, newText: string) => Promise<void>) => Promise<void>;
|
|
5
5
|
logErrors: (fileName: string, diagnostics: Diagnostic[]) => void;
|
package/out/createLinter.js
CHANGED
|
@@ -3,16 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createLinter = void 0;
|
|
4
4
|
const language_service_1 = require("@volar/language-service");
|
|
5
5
|
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
6
|
-
const vscode_uri_1 = require("vscode-uri");
|
|
7
6
|
const utils_1 = require("./utils");
|
|
7
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
8
8
|
function createLinter(config, host) {
|
|
9
9
|
let settings = {};
|
|
10
10
|
const ts = require('typescript');
|
|
11
11
|
const service = (0, language_service_1.createLanguageService)({ typescript: ts }, {
|
|
12
12
|
uriToFileName: utils_1.uriToFileName,
|
|
13
13
|
fileNameToUri: utils_1.fileNameToUri,
|
|
14
|
-
rootUri: vscode_uri_1.URI.
|
|
14
|
+
rootUri: vscode_uri_1.URI.parse((0, utils_1.fileNameToUri)(host.getCurrentDirectory())),
|
|
15
15
|
getConfiguration: section => (0, utils_1.getConfiguration)(settings, section),
|
|
16
|
+
fs: utils_1.fs,
|
|
16
17
|
}, config, host);
|
|
17
18
|
return {
|
|
18
19
|
check,
|
|
@@ -91,9 +92,9 @@ function createLinter(config, host) {
|
|
|
91
92
|
messageText: diagnostic.message,
|
|
92
93
|
}));
|
|
93
94
|
const text = ts.formatDiagnosticsWithColorAndContext(errors, {
|
|
94
|
-
getCurrentDirectory: () => rootPath
|
|
95
|
-
getCanonicalFileName: (fileName) =>
|
|
96
|
-
getNewLine: () =>
|
|
95
|
+
getCurrentDirectory: () => rootPath,
|
|
96
|
+
getCanonicalFileName: (fileName) => ts.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
|
|
97
|
+
getNewLine: () => ts.sys.newLine,
|
|
97
98
|
});
|
|
98
99
|
return text;
|
|
99
100
|
}
|
package/out/createProject.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TypeScriptLanguageHost } from '@volar/language-service';
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
3
|
export declare function createInferredProject(rootPath: string, getScriptFileNames: () => string[], compilerOptions?: ts.CompilerOptions): {
|
|
4
|
-
|
|
5
|
-
isKnownRelatedFile: (fileName: string) => boolean;
|
|
4
|
+
languageHost: TypeScriptLanguageHost;
|
|
6
5
|
fileUpdated(fileName: string): void;
|
|
7
6
|
fileDeleted(fileName: string): void;
|
|
8
7
|
fileCreated(fileName: string): void;
|
|
9
8
|
reload(): void;
|
|
10
9
|
};
|
|
11
10
|
export declare function createProject(sourceTsconfigPath: string, extraFileExtensions?: ts.FileExtensionInfo[], existingOptions?: ts.CompilerOptions): {
|
|
12
|
-
|
|
13
|
-
isKnownRelatedFile: (fileName: string) => boolean;
|
|
11
|
+
languageHost: TypeScriptLanguageHost;
|
|
14
12
|
fileUpdated(fileName: string): void;
|
|
15
13
|
fileDeleted(fileName: string): void;
|
|
16
14
|
fileCreated(fileName: string): void;
|
package/out/createProject.js
CHANGED
|
@@ -22,82 +22,69 @@ function createProject(sourceTsconfigPath, extraFileExtensions = [], existingOpt
|
|
|
22
22
|
exports.createProject = createProject;
|
|
23
23
|
function createProjectBase(rootPath, createParsedCommandLine) {
|
|
24
24
|
const ts = require('typescript');
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
const languageHost = {
|
|
26
|
+
getCurrentDirectory: () => {
|
|
27
|
+
return rootPath;
|
|
28
|
+
},
|
|
29
|
+
getCompilationSettings: () => {
|
|
30
|
+
return parsedCommandLine.options;
|
|
31
|
+
},
|
|
32
32
|
getProjectVersion: () => {
|
|
33
33
|
checkRootFilesUpdate();
|
|
34
|
-
return projectVersion
|
|
35
|
-
},
|
|
36
|
-
getTypeRootsVersion: () => {
|
|
37
|
-
return typeRootsVersion;
|
|
34
|
+
return projectVersion;
|
|
38
35
|
},
|
|
39
36
|
getScriptFileNames: () => {
|
|
40
37
|
checkRootFilesUpdate();
|
|
41
38
|
return parsedCommandLine.fileNames;
|
|
42
39
|
},
|
|
43
|
-
getScriptVersion: (fileName) =>
|
|
40
|
+
getScriptVersion: (fileName) => {
|
|
41
|
+
return scriptVersions.get(fileName)?.toString();
|
|
42
|
+
},
|
|
44
43
|
getScriptSnapshot: (fileName) => {
|
|
45
|
-
|
|
46
|
-
if (!scriptSnapshots[fileName] || scriptSnapshots[fileName][0] !== version) {
|
|
44
|
+
if (!scriptSnapshotsCache.has(fileName)) {
|
|
47
45
|
const fileText = ts.sys.readFile(fileName, 'utf8');
|
|
48
46
|
if (fileText !== undefined) {
|
|
49
|
-
|
|
47
|
+
scriptSnapshotsCache.set(fileName, ts.ScriptSnapshot.fromString(fileText));
|
|
50
48
|
}
|
|
51
49
|
else {
|
|
52
|
-
|
|
50
|
+
scriptSnapshotsCache.set(fileName, undefined);
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
return
|
|
53
|
+
return scriptSnapshotsCache.get(fileName);
|
|
56
54
|
},
|
|
57
55
|
};
|
|
58
|
-
let
|
|
59
|
-
let scriptVersions =
|
|
60
|
-
let scriptSnapshots = {};
|
|
56
|
+
let scriptSnapshotsCache = new Map();
|
|
57
|
+
let scriptVersions = new Map();
|
|
61
58
|
let parsedCommandLine = createParsedCommandLine();
|
|
62
59
|
let projectVersion = 0;
|
|
63
|
-
let typeRootsVersion = 0;
|
|
64
60
|
let shouldCheckRootFiles = false;
|
|
65
61
|
return {
|
|
66
|
-
|
|
67
|
-
isKnownRelatedFile,
|
|
62
|
+
languageHost,
|
|
68
63
|
fileUpdated(fileName) {
|
|
64
|
+
scriptVersions.set(fileName, (scriptVersions.get(fileName) ?? 0) + 1);
|
|
69
65
|
fileName = (0, utils_1.asPosix)(fileName);
|
|
70
|
-
if (
|
|
66
|
+
if (scriptSnapshotsCache.has(fileName)) {
|
|
71
67
|
projectVersion++;
|
|
72
|
-
|
|
73
|
-
scriptVersions[fileName]++;
|
|
68
|
+
scriptSnapshotsCache.delete(fileName);
|
|
74
69
|
}
|
|
75
70
|
},
|
|
76
71
|
fileDeleted(fileName) {
|
|
72
|
+
scriptVersions.set(fileName, (scriptVersions.get(fileName) ?? 0) + 1);
|
|
77
73
|
fileName = (0, utils_1.asPosix)(fileName);
|
|
78
|
-
|
|
79
|
-
if (isKnownRelatedFile(fileName)) {
|
|
74
|
+
if (scriptSnapshotsCache.has(fileName)) {
|
|
80
75
|
projectVersion++;
|
|
81
|
-
delete
|
|
82
|
-
delete scriptSnapshots[fileName];
|
|
76
|
+
scriptSnapshotsCache.delete(fileName);
|
|
83
77
|
parsedCommandLine.fileNames = parsedCommandLine.fileNames.filter(name => name !== fileName);
|
|
84
78
|
}
|
|
85
79
|
},
|
|
86
80
|
fileCreated(fileName) {
|
|
81
|
+
scriptVersions.set(fileName, (scriptVersions.get(fileName) ?? 0) + 1);
|
|
87
82
|
fileName = (0, utils_1.asPosix)(fileName);
|
|
88
|
-
if (isKnownRelatedFile(fileName)) {
|
|
89
|
-
projectVersion++;
|
|
90
|
-
typeRootsVersion++;
|
|
91
|
-
}
|
|
92
83
|
shouldCheckRootFiles = true;
|
|
93
|
-
fileExistsCache[fileName] = true;
|
|
94
|
-
scriptVersions[fileName] ??= 0;
|
|
95
|
-
scriptVersions[fileName]++;
|
|
96
84
|
},
|
|
97
85
|
reload() {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
scriptSnapshots = {};
|
|
86
|
+
scriptVersions.clear();
|
|
87
|
+
scriptSnapshotsCache.clear();
|
|
101
88
|
projectVersion++;
|
|
102
89
|
parsedCommandLine = createParsedCommandLine();
|
|
103
90
|
},
|
|
@@ -112,12 +99,5 @@ function createProjectBase(rootPath, createParsedCommandLine) {
|
|
|
112
99
|
projectVersion++;
|
|
113
100
|
}
|
|
114
101
|
}
|
|
115
|
-
function fileExists(fileName) {
|
|
116
|
-
fileExistsCache[fileName] ??= ts.sys.fileExists(fileName);
|
|
117
|
-
return fileExistsCache[fileName];
|
|
118
|
-
}
|
|
119
|
-
function isKnownRelatedFile(fileName) {
|
|
120
|
-
return scriptSnapshots[fileName] !== undefined || fileExistsCache[fileName] !== undefined;
|
|
121
|
-
}
|
|
122
102
|
}
|
|
123
103
|
//# sourceMappingURL=createProject.js.map
|
package/out/utils.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as path from 'typesafe-path/posix';
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
+
import { FileSystem } from '@volar/language-service';
|
|
3
4
|
export declare const defaultCompilerOptions: ts.CompilerOptions;
|
|
4
5
|
export declare function asPosix(path: string): path.PosixPath;
|
|
5
6
|
export declare const uriToFileName: (uri: string) => string;
|
|
6
7
|
export declare const fileNameToUri: (fileName: string) => string;
|
|
7
8
|
export declare function getConfiguration(settings: any, section: string): any;
|
|
9
|
+
export declare const fs: FileSystem;
|
package/out/utils.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getConfiguration = exports.fileNameToUri = exports.uriToFileName = exports.asPosix = exports.defaultCompilerOptions = void 0;
|
|
3
|
+
exports.fs = exports.getConfiguration = exports.fileNameToUri = exports.uriToFileName = exports.asPosix = exports.defaultCompilerOptions = void 0;
|
|
4
4
|
const vscode_uri_1 = require("vscode-uri");
|
|
5
|
+
const language_service_1 = require("@volar/language-service");
|
|
6
|
+
const _fs = require("fs");
|
|
5
7
|
exports.defaultCompilerOptions = {
|
|
6
8
|
allowJs: true,
|
|
7
9
|
allowSyntheticDefaultImports: true,
|
|
@@ -41,4 +43,38 @@ function getConfiguration(settings, section) {
|
|
|
41
43
|
return result;
|
|
42
44
|
}
|
|
43
45
|
exports.getConfiguration = getConfiguration;
|
|
46
|
+
exports.fs = {
|
|
47
|
+
readFile(uri, encoding) {
|
|
48
|
+
return _fs.readFileSync((0, exports.uriToFileName)(uri), { encoding: encoding ?? 'utf8' });
|
|
49
|
+
},
|
|
50
|
+
readDirectory(uri) {
|
|
51
|
+
if (uri.startsWith('file://')) {
|
|
52
|
+
const dirName = (0, exports.uriToFileName)(uri);
|
|
53
|
+
const files = _fs.existsSync(dirName) ? _fs.readdirSync(dirName, { withFileTypes: true }) : [];
|
|
54
|
+
return files.map(file => {
|
|
55
|
+
return [file.name, file.isFile() ? language_service_1.FileType.File
|
|
56
|
+
: file.isDirectory() ? language_service_1.FileType.Directory
|
|
57
|
+
: file.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
|
|
58
|
+
: language_service_1.FileType.Unknown];
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return [];
|
|
62
|
+
},
|
|
63
|
+
stat(uri) {
|
|
64
|
+
if (uri.startsWith('file://')) {
|
|
65
|
+
const stats = _fs.statSync((0, exports.uriToFileName)(uri), { throwIfNoEntry: false });
|
|
66
|
+
if (stats) {
|
|
67
|
+
return {
|
|
68
|
+
type: stats.isFile() ? language_service_1.FileType.File
|
|
69
|
+
: stats.isDirectory() ? language_service_1.FileType.Directory
|
|
70
|
+
: stats.isSymbolicLink() ? language_service_1.FileType.SymbolicLink
|
|
71
|
+
: language_service_1.FileType.Unknown,
|
|
72
|
+
ctime: stats.ctimeMs,
|
|
73
|
+
mtime: stats.mtimeMs,
|
|
74
|
+
size: stats.size,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
};
|
|
44
80
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,12 +13,13 @@
|
|
|
13
13
|
"directory": "packages/kit"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-service": "1.
|
|
16
|
+
"@volar/language-service": "1.7.0",
|
|
17
17
|
"typesafe-path": "^0.2.2",
|
|
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": "38ec4f727b32dbf2cf3284ab02695e3a8effacc5"
|
|
24
25
|
}
|