volar-service-typescript 0.0.0 → 0.0.2
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 +10 -1
- package/out/index.js +50 -24
- package/package.json +2 -3
- package/rules.d.ts +0 -13
package/out/index.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { InjectionKey, Service } from '@volar/language-service';
|
|
2
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
|
+
export declare const injectionKeys: {
|
|
5
|
+
typescript: InjectionKey<[], typeof import('typescript/lib/tsserverlibrary')>;
|
|
6
|
+
sourceFile: InjectionKey<[TextDocument], ts.SourceFile>;
|
|
7
|
+
languageService: InjectionKey<[TextDocument], ts.LanguageService>;
|
|
8
|
+
languageServiceHost: InjectionKey<[TextDocument], ts.LanguageServiceHost>;
|
|
9
|
+
textDocument: InjectionKey<[uri: string], TextDocument>;
|
|
10
|
+
};
|
|
2
11
|
declare const _default: () => Service;
|
|
3
12
|
export default _default;
|
package/out/index.js
CHANGED
|
@@ -23,6 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.injectionKeys = void 0;
|
|
27
|
+
const language_service_1 = require("@volar/language-service");
|
|
26
28
|
const semver = __importStar(require("semver"));
|
|
27
29
|
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
28
30
|
const shared_1 = require("./shared");
|
|
@@ -53,6 +55,13 @@ const signatureHelp = __importStar(require("./services/signatureHelp"));
|
|
|
53
55
|
const typeDefinitions = __importStar(require("./services/typeDefinition"));
|
|
54
56
|
const workspaceSymbols = __importStar(require("./services/workspaceSymbol"));
|
|
55
57
|
const tsconfig = __importStar(require("./services/tsconfig"));
|
|
58
|
+
exports.injectionKeys = {
|
|
59
|
+
typescript: 'typescript/typescript',
|
|
60
|
+
sourceFile: 'typescript/sourceFile',
|
|
61
|
+
languageService: 'typescript/languageService',
|
|
62
|
+
languageServiceHost: 'typescript/languageServiceHost',
|
|
63
|
+
textDocument: 'typescript/textDocument',
|
|
64
|
+
};
|
|
56
65
|
exports.default = () => (contextOrNull, modules) => {
|
|
57
66
|
const jsDocTriggerCharacter = '*';
|
|
58
67
|
const directiveCommentTriggerCharacter = '@';
|
|
@@ -72,7 +81,7 @@ exports.default = () => (contextOrNull, modules) => {
|
|
|
72
81
|
}
|
|
73
82
|
const context = contextOrNull;
|
|
74
83
|
if (!modules?.typescript) {
|
|
75
|
-
console.warn('[volar-service-typescript] context.typescript not found,
|
|
84
|
+
console.warn('[volar-service-typescript] context.typescript not found, volar-service-typescript is disabled. Make sure you have provide tsdk in language client.');
|
|
76
85
|
return {};
|
|
77
86
|
}
|
|
78
87
|
const ts = modules.typescript;
|
|
@@ -113,6 +122,7 @@ exports.default = () => (contextOrNull, modules) => {
|
|
|
113
122
|
const callHierarchy = _callHierarchy.register(semanticCtx);
|
|
114
123
|
const tsconfigRequests = tsconfig.register(semanticCtx);
|
|
115
124
|
let syntacticHostCtx = {
|
|
125
|
+
document: undefined,
|
|
116
126
|
fileName: '',
|
|
117
127
|
fileVersion: 0,
|
|
118
128
|
snapshot: ts.ScriptSnapshot.fromString(''),
|
|
@@ -140,35 +150,42 @@ exports.default = () => (contextOrNull, modules) => {
|
|
|
140
150
|
const doFormatting = formatting.register(syntacticCtx);
|
|
141
151
|
const getFoldingRanges = foldingRanges.register(syntacticCtx);
|
|
142
152
|
return {
|
|
153
|
+
provide: {
|
|
154
|
+
...(0, language_service_1.defineProvide)(exports.injectionKeys.typescript, () => ts),
|
|
155
|
+
...(0, language_service_1.defineProvide)(exports.injectionKeys.sourceFile, document => {
|
|
156
|
+
if ((0, shared_1.isTsDocument)(document)) {
|
|
157
|
+
const sourceFile = getSemanticServiceSourceFile(document.uri);
|
|
158
|
+
if (sourceFile) {
|
|
159
|
+
return sourceFile;
|
|
160
|
+
}
|
|
161
|
+
prepareSyntacticService(document);
|
|
162
|
+
return syntacticCtx.typescript.languageService.getProgram()?.getSourceFile(syntacticHostCtx.fileName);
|
|
163
|
+
}
|
|
164
|
+
}),
|
|
165
|
+
...(0, language_service_1.defineProvide)(exports.injectionKeys.languageService, document => {
|
|
166
|
+
const sourceFile = getSemanticServiceSourceFile(document.uri);
|
|
167
|
+
if (sourceFile) {
|
|
168
|
+
return semanticCtx.typescript.languageService;
|
|
169
|
+
}
|
|
170
|
+
prepareSyntacticService(document);
|
|
171
|
+
return syntacticCtx.typescript.languageService;
|
|
172
|
+
}),
|
|
173
|
+
...(0, language_service_1.defineProvide)(exports.injectionKeys.languageServiceHost, document => {
|
|
174
|
+
const sourceFile = getSemanticServiceSourceFile(document.uri);
|
|
175
|
+
if (sourceFile) {
|
|
176
|
+
return semanticCtx.typescript.languageServiceHost;
|
|
177
|
+
}
|
|
178
|
+
prepareSyntacticService(document);
|
|
179
|
+
return syntacticCtx.typescript.languageServiceHost;
|
|
180
|
+
}),
|
|
181
|
+
...(0, language_service_1.defineProvide)(exports.injectionKeys.textDocument, semanticCtx.getTextDocument),
|
|
182
|
+
},
|
|
143
183
|
...triggerCharacters,
|
|
144
184
|
triggerCharacters: [
|
|
145
185
|
...basicTriggerCharacters,
|
|
146
186
|
jsDocTriggerCharacter,
|
|
147
187
|
directiveCommentTriggerCharacter,
|
|
148
188
|
],
|
|
149
|
-
resolveRuleContext(ruleCtx, type) {
|
|
150
|
-
if ((0, shared_1.isTsDocument)(ruleCtx.document)) {
|
|
151
|
-
let sourceFile;
|
|
152
|
-
if (type === 'format' || type === 'syntax') {
|
|
153
|
-
prepareSyntacticService(ruleCtx.document);
|
|
154
|
-
sourceFile = syntacticCtx.typescript.languageService.getProgram()?.getSourceFile(syntacticHostCtx.fileName);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
sourceFile = semanticCtx.typescript.languageService.getProgram()?.getSourceFile(context.env.uriToFileName(ruleCtx.document.uri));
|
|
158
|
-
}
|
|
159
|
-
if (sourceFile) {
|
|
160
|
-
ruleCtx.typescript = {
|
|
161
|
-
sourceFile,
|
|
162
|
-
getTextDocument: syntacticCtx.getTextDocument,
|
|
163
|
-
...syntacticCtx.typescript,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
console.warn('[volar-service-typescript] sourceFile not found', ruleCtx.document.uri);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return ruleCtx;
|
|
171
|
-
},
|
|
172
189
|
provideAutoInsertionEdit(document, position, ctx) {
|
|
173
190
|
if ((document.languageId === 'javascriptreact' || document.languageId === 'typescriptreact')
|
|
174
191
|
&& ctx.lastChange.text.endsWith('>')) {
|
|
@@ -381,7 +398,16 @@ exports.default = () => (contextOrNull, modules) => {
|
|
|
381
398
|
return tsconfigRequests.resolve(link, token);
|
|
382
399
|
},
|
|
383
400
|
};
|
|
401
|
+
function getSemanticServiceSourceFile(uri) {
|
|
402
|
+
const sourceFile = semanticCtx.typescript.languageService.getProgram()?.getSourceFile(context.env.uriToFileName(uri));
|
|
403
|
+
if (sourceFile) {
|
|
404
|
+
return sourceFile;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
384
407
|
function prepareSyntacticService(document) {
|
|
408
|
+
if (syntacticHostCtx.document === document && syntacticHostCtx.fileVersion === document.version) {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
385
411
|
syntacticHostCtx.fileName = context.env.uriToFileName(document.uri);
|
|
386
412
|
syntacticHostCtx.fileVersion = document.version;
|
|
387
413
|
if (context.documents.isVirtualFileUri(document.uri)) {
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "volar-service-typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
|
-
"rules.d.ts",
|
|
8
7
|
"out/**/*.js",
|
|
9
8
|
"out/**/*.d.ts"
|
|
10
9
|
],
|
|
@@ -28,5 +27,5 @@
|
|
|
28
27
|
"peerDependencies": {
|
|
29
28
|
"@volar/language-service": "*"
|
|
30
29
|
},
|
|
31
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "19482084693c7349f461dc75ec52ee6917739c51"
|
|
32
31
|
}
|
package/rules.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
-
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
3
|
-
|
|
4
|
-
declare module '@volar/language-service' {
|
|
5
|
-
interface RuleContext {
|
|
6
|
-
typescript?: {
|
|
7
|
-
sourceFile: ts.SourceFile;
|
|
8
|
-
getTextDocument(uri: string): TextDocument | undefined;
|
|
9
|
-
languageService: ts.LanguageService;
|
|
10
|
-
languageServiceHost: ts.LanguageServiceHost;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|