volar-service-typescript 0.0.36 → 0.0.37
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.
|
@@ -11,7 +11,7 @@ function create(ts) {
|
|
|
11
11
|
return {
|
|
12
12
|
name: 'typescript-doc-comment-template',
|
|
13
13
|
triggerCharacters: ['*'],
|
|
14
|
-
create(
|
|
14
|
+
create() {
|
|
15
15
|
return {
|
|
16
16
|
provideCompletionItems(document, position) {
|
|
17
17
|
if (!(0, shared_1.isTsDocument)(document)) {
|
|
@@ -20,7 +20,7 @@ function create(ts) {
|
|
|
20
20
|
if (!isPotentiallyValidDocCompletionPosition(document, position)) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
const { languageService, fileName } = (0, syntactic_1.getLanguageServiceByDocument)(
|
|
23
|
+
const { languageService, fileName } = (0, syntactic_1.getLanguageServiceByDocument)(ts, document);
|
|
24
24
|
const offset = document.offsetAt(position);
|
|
25
25
|
const docCommentTemplate = languageService.getDocCommentTemplateAtPosition(fileName, offset);
|
|
26
26
|
if (!docCommentTemplate) {
|
|
@@ -4,8 +4,9 @@ export declare function create(ts: typeof import('typescript'), { isFormattingEn
|
|
|
4
4
|
isFormattingEnabled?(document: TextDocument, context: ServiceContext): ProviderResult<boolean>;
|
|
5
5
|
isAutoClosingTagsEnabled?(document: TextDocument, context: ServiceContext): ProviderResult<boolean>;
|
|
6
6
|
}): LanguageServicePlugin;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import type * as ts from 'typescript';
|
|
8
|
+
export declare function getLanguageServiceByDocument(ts: typeof import('typescript'), document: TextDocument): {
|
|
9
|
+
languageService: ts.LanguageService;
|
|
9
10
|
fileName: string;
|
|
10
11
|
};
|
|
11
12
|
//# sourceMappingURL=syntactic.d.ts.map
|
package/lib/plugins/syntactic.js
CHANGED
|
@@ -20,7 +20,7 @@ function create(ts, { isFormattingEnabled = async (document, context) => {
|
|
|
20
20
|
if ((document.languageId === 'javascriptreact' || document.languageId === 'typescriptreact')
|
|
21
21
|
&& lastChange.text.endsWith('>')
|
|
22
22
|
&& await isAutoClosingTagsEnabled(document, context)) {
|
|
23
|
-
const { languageService, fileName } = getLanguageServiceByDocument(
|
|
23
|
+
const { languageService, fileName } = getLanguageServiceByDocument(ts, document);
|
|
24
24
|
const close = languageService.getJsxClosingTagAtPosition(fileName, document.offsetAt(position));
|
|
25
25
|
if (close) {
|
|
26
26
|
return '$0' + close.newText;
|
|
@@ -31,7 +31,7 @@ function create(ts, { isFormattingEnabled = async (document, context) => {
|
|
|
31
31
|
if (!(0, shared_1.isTsDocument)(document)) {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
const { languageService, fileName } = getLanguageServiceByDocument(
|
|
34
|
+
const { languageService, fileName } = getLanguageServiceByDocument(ts, document);
|
|
35
35
|
const outliningSpans = (0, shared_1.safeCall)(() => languageService.getOutliningSpans(fileName));
|
|
36
36
|
if (!outliningSpans) {
|
|
37
37
|
return [];
|
|
@@ -42,7 +42,7 @@ function create(ts, { isFormattingEnabled = async (document, context) => {
|
|
|
42
42
|
if (!(0, shared_1.isTsDocument)(document)) {
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
const { languageService, fileName } = getLanguageServiceByDocument(
|
|
45
|
+
const { languageService, fileName } = getLanguageServiceByDocument(ts, document);
|
|
46
46
|
const barItems = (0, shared_1.safeCall)(() => languageService.getNavigationTree(fileName));
|
|
47
47
|
if (!barItems) {
|
|
48
48
|
return [];
|
|
@@ -64,7 +64,7 @@ function create(ts, { isFormattingEnabled = async (document, context) => {
|
|
|
64
64
|
if (codeOptions) {
|
|
65
65
|
tsOptions.baseIndentSize = codeOptions.initialIndentLevel * options.tabSize;
|
|
66
66
|
}
|
|
67
|
-
const { languageService, fileName } = getLanguageServiceByDocument(
|
|
67
|
+
const { languageService, fileName } = getLanguageServiceByDocument(ts, document);
|
|
68
68
|
const scriptEdits = range
|
|
69
69
|
? (0, shared_1.safeCall)(() => languageService.getFormattingEditsForRange(fileName, document.offsetAt(range.start), document.offsetAt(range.end), tsOptions))
|
|
70
70
|
: (0, shared_1.safeCall)(() => languageService.getFormattingEditsForDocument(fileName, tsOptions));
|
|
@@ -84,7 +84,7 @@ function create(ts, { isFormattingEnabled = async (document, context) => {
|
|
|
84
84
|
if (codeOptions) {
|
|
85
85
|
tsOptions.baseIndentSize = codeOptions.initialIndentLevel * options.tabSize;
|
|
86
86
|
}
|
|
87
|
-
const { languageService, fileName } = getLanguageServiceByDocument(
|
|
87
|
+
const { languageService, fileName } = getLanguageServiceByDocument(ts, document);
|
|
88
88
|
const scriptEdits = (0, shared_1.safeCall)(() => languageService.getFormattingEditsAfterKeystroke(fileName, document.offsetAt(position), key, tsOptions));
|
|
89
89
|
if (!scriptEdits) {
|
|
90
90
|
return [];
|
|
@@ -96,23 +96,15 @@ function create(ts, { isFormattingEnabled = async (document, context) => {
|
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
exports.create = create;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return (0, syntacticLanguageService_1.getLanguageService)(ts, embeddedCode.snapshot, document.languageId, true);
|
|
107
|
-
}
|
|
99
|
+
const snapshots = new WeakMap();
|
|
100
|
+
function getLanguageServiceByDocument(ts, document) {
|
|
101
|
+
let cache = snapshots.get(document);
|
|
102
|
+
if (!cache || cache[0] !== document.version) {
|
|
103
|
+
const snapshot = ts.ScriptSnapshot.fromString(document.getText());
|
|
104
|
+
cache = [document.version, snapshot];
|
|
105
|
+
snapshots.set(document, cache);
|
|
108
106
|
}
|
|
109
|
-
|
|
110
|
-
const sourceScript = context.language.scripts.get(document.uri);
|
|
111
|
-
if (sourceScript) {
|
|
112
|
-
return (0, syntacticLanguageService_1.getLanguageService)(ts, sourceScript.snapshot, document.languageId, true);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
throw new Error(`No language service for ${document.uri}`);
|
|
107
|
+
return (0, syntacticLanguageService_1.getLanguageService)(ts, cache[1], document.languageId, true);
|
|
116
108
|
}
|
|
117
109
|
exports.getLanguageServiceByDocument = getLanguageServiceByDocument;
|
|
118
110
|
//# sourceMappingURL=syntactic.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"description": "Integrate TypeScript into Volar",
|
|
5
5
|
"homepage": "https://github.com/volarjs/services/tree/master/packages/typescript",
|
|
6
6
|
"bugs": "https://github.com/volarjs/services/issues",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"optional": true
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "ee14afba19f419a31c4b70e5a34f88cefb59ac49"
|
|
46
46
|
}
|