volar-service-typescript 0.0.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/out/configs/getFormatCodeSettings.d.ts +5 -0
- package/out/configs/getFormatCodeSettings.js +34 -0
- package/out/configs/getUserPreferences.d.ts +4 -0
- package/out/configs/getUserPreferences.js +97 -0
- package/out/index.d.ts +3 -0
- package/out/index.js +421 -0
- package/out/protocol.const.d.ts +72 -0
- package/out/protocol.const.js +92 -0
- package/out/services/callHierarchy.d.ts +7 -0
- package/out/services/callHierarchy.js +126 -0
- package/out/services/codeAction.d.ts +26 -0
- package/out/services/codeAction.js +242 -0
- package/out/services/codeActionResolve.d.ts +9 -0
- package/out/services/codeActionResolve.js +51 -0
- package/out/services/completions/basic.d.ts +16 -0
- package/out/services/completions/basic.js +322 -0
- package/out/services/completions/directiveComment.d.ts +3 -0
- package/out/services/completions/directiveComment.js +69 -0
- package/out/services/completions/jsDoc.d.ts +3 -0
- package/out/services/completions/jsDoc.js +106 -0
- package/out/services/completions/resolve.d.ts +5 -0
- package/out/services/completions/resolve.js +170 -0
- package/out/services/definition.d.ts +3 -0
- package/out/services/definition.js +20 -0
- package/out/services/diagnostics.d.ts +10 -0
- package/out/services/diagnostics.js +144 -0
- package/out/services/documentHighlight.d.ts +3 -0
- package/out/services/documentHighlight.js +56 -0
- package/out/services/documentSymbol.d.ts +3 -0
- package/out/services/documentSymbol.js +106 -0
- package/out/services/fileReferences.d.ts +3 -0
- package/out/services/fileReferences.js +19 -0
- package/out/services/fileRename.d.ts +3 -0
- package/out/services/fileRename.js +25 -0
- package/out/services/foldingRanges.d.ts +3 -0
- package/out/services/foldingRanges.js +73 -0
- package/out/services/formatting.d.ts +6 -0
- package/out/services/formatting.js +58 -0
- package/out/services/hover.d.ts +3 -0
- package/out/services/hover.js +64 -0
- package/out/services/implementation.d.ts +3 -0
- package/out/services/implementation.js +20 -0
- package/out/services/inlayHints.d.ts +3 -0
- package/out/services/inlayHints.js +54 -0
- package/out/services/prepareRename.d.ts +6 -0
- package/out/services/prepareRename.js +51 -0
- package/out/services/references.d.ts +3 -0
- package/out/services/references.js +20 -0
- package/out/services/rename.d.ts +5 -0
- package/out/services/rename.js +135 -0
- package/out/services/selectionRanges.d.ts +3 -0
- package/out/services/selectionRanges.js +53 -0
- package/out/services/semanticTokens.d.ts +3 -0
- package/out/services/semanticTokens.js +128 -0
- package/out/services/signatureHelp.d.ts +3 -0
- package/out/services/signatureHelp.js +87 -0
- package/out/services/tsconfig.d.ts +6 -0
- package/out/services/tsconfig.js +199 -0
- package/out/services/typeDefinition.d.ts +3 -0
- package/out/services/typeDefinition.js +20 -0
- package/out/services/workspaceSymbol.d.ts +3 -0
- package/out/services/workspaceSymbol.js +80 -0
- package/out/shared.d.ts +5 -0
- package/out/shared.js +33 -0
- package/out/types.d.ts +5 -0
- package/out/types.js +3 -0
- package/out/utils/errorCodes.d.ts +11 -0
- package/out/utils/errorCodes.js +19 -0
- package/out/utils/fixNames.d.ts +13 -0
- package/out/utils/fixNames.js +21 -0
- package/out/utils/modifiers.d.ts +1 -0
- package/out/utils/modifiers.js +12 -0
- package/out/utils/previewer.d.ts +13 -0
- package/out/utils/previewer.js +182 -0
- package/out/utils/snippetForFunctionCall.d.ts +8 -0
- package/out/utils/snippetForFunctionCall.js +112 -0
- package/out/utils/transforms.d.ts +10 -0
- package/out/utils/transforms.js +76 -0
- package/out/utils/typeConverters.d.ts +4 -0
- package/out/utils/typeConverters.js +67 -0
- package/package.json +32 -0
- package/rules.d.ts +13 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = void 0;
|
|
4
|
+
const getFormatCodeSettings_1 = require("../configs/getFormatCodeSettings");
|
|
5
|
+
const shared_1 = require("../shared");
|
|
6
|
+
function register(ctx) {
|
|
7
|
+
return {
|
|
8
|
+
onRange: async (uri, range, options) => {
|
|
9
|
+
const document = ctx.getTextDocument(uri);
|
|
10
|
+
if (!document)
|
|
11
|
+
return [];
|
|
12
|
+
const fileName = ctx.env.uriToFileName(document.uri);
|
|
13
|
+
const tsOptions = await (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, options);
|
|
14
|
+
if (typeof (tsOptions.indentSize) === "boolean" || typeof (tsOptions.indentSize) === "string") {
|
|
15
|
+
tsOptions.indentSize = undefined;
|
|
16
|
+
}
|
|
17
|
+
const scriptEdits = range
|
|
18
|
+
? (0, shared_1.safeCall)(() => ctx.typescript.languageService.getFormattingEditsForRange(fileName, document.offsetAt(range.start), document.offsetAt(range.end), tsOptions))
|
|
19
|
+
: (0, shared_1.safeCall)(() => ctx.typescript.languageService.getFormattingEditsForDocument(fileName, tsOptions));
|
|
20
|
+
if (!scriptEdits)
|
|
21
|
+
return [];
|
|
22
|
+
const result = [];
|
|
23
|
+
for (const textEdit of scriptEdits) {
|
|
24
|
+
result.push({
|
|
25
|
+
range: {
|
|
26
|
+
start: document.positionAt(textEdit.span.start),
|
|
27
|
+
end: document.positionAt(textEdit.span.start + textEdit.span.length),
|
|
28
|
+
},
|
|
29
|
+
newText: textEdit.newText,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
},
|
|
34
|
+
onType: async (uri, options, position, key) => {
|
|
35
|
+
const document = ctx.getTextDocument(uri);
|
|
36
|
+
if (!document)
|
|
37
|
+
return [];
|
|
38
|
+
const fileName = ctx.env.uriToFileName(document.uri);
|
|
39
|
+
const tsOptions = await (0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document, options);
|
|
40
|
+
const scriptEdits = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getFormattingEditsAfterKeystroke(fileName, document.offsetAt(position), key, tsOptions));
|
|
41
|
+
if (!scriptEdits)
|
|
42
|
+
return [];
|
|
43
|
+
const result = [];
|
|
44
|
+
for (const textEdit of scriptEdits) {
|
|
45
|
+
result.push({
|
|
46
|
+
range: {
|
|
47
|
+
start: document.positionAt(textEdit.span.start),
|
|
48
|
+
end: document.positionAt(textEdit.span.start + textEdit.span.length),
|
|
49
|
+
},
|
|
50
|
+
newText: textEdit.newText,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
exports.register = register;
|
|
58
|
+
//# sourceMappingURL=formatting.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.register = void 0;
|
|
27
|
+
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
28
|
+
const previewer = __importStar(require("../utils/previewer"));
|
|
29
|
+
const shared_1 = require("../shared");
|
|
30
|
+
function register(ctx) {
|
|
31
|
+
const { ts } = ctx;
|
|
32
|
+
return (uri, position, documentOnly = false) => {
|
|
33
|
+
const document = ctx.getTextDocument(uri);
|
|
34
|
+
if (!document)
|
|
35
|
+
return;
|
|
36
|
+
const fileName = ctx.env.uriToFileName(document.uri);
|
|
37
|
+
const offset = document.offsetAt(position);
|
|
38
|
+
const info = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getQuickInfoAtPosition(fileName, offset));
|
|
39
|
+
if (!info)
|
|
40
|
+
return;
|
|
41
|
+
const parts = [];
|
|
42
|
+
const displayString = ts.displayPartsToString(info.displayParts);
|
|
43
|
+
const documentation = previewer.markdownDocumentation(info.documentation ?? [], info.tags, { toResource }, ctx);
|
|
44
|
+
if (displayString && !documentOnly) {
|
|
45
|
+
parts.push(['```typescript', displayString, '```'].join('\n'));
|
|
46
|
+
}
|
|
47
|
+
if (documentation) {
|
|
48
|
+
parts.push(documentation);
|
|
49
|
+
}
|
|
50
|
+
const markdown = {
|
|
51
|
+
kind: vscode.MarkupKind.Markdown,
|
|
52
|
+
value: parts.join('\n\n'),
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
contents: markdown,
|
|
56
|
+
range: vscode.Range.create(document.positionAt(info.textSpan.start), document.positionAt(info.textSpan.start + info.textSpan.length)),
|
|
57
|
+
};
|
|
58
|
+
function toResource(path) {
|
|
59
|
+
return ctx.env.fileNameToUri(path);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.register = register;
|
|
64
|
+
//# sourceMappingURL=hover.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = void 0;
|
|
4
|
+
const transforms_1 = require("../utils/transforms");
|
|
5
|
+
const shared_1 = require("../shared");
|
|
6
|
+
function register(ctx) {
|
|
7
|
+
return (uri, position) => {
|
|
8
|
+
const document = ctx.getTextDocument(uri);
|
|
9
|
+
if (!document)
|
|
10
|
+
return [];
|
|
11
|
+
const fileName = ctx.env.uriToFileName(document.uri);
|
|
12
|
+
const offset = document.offsetAt(position);
|
|
13
|
+
const entries = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getImplementationAtPosition(fileName, offset));
|
|
14
|
+
if (!entries)
|
|
15
|
+
return [];
|
|
16
|
+
return (0, transforms_1.entriesToLocationLinks)([...entries], ctx);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.register = register;
|
|
20
|
+
//# sourceMappingURL=implementation.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.register = void 0;
|
|
27
|
+
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
28
|
+
const getUserPreferences_1 = require("../configs/getUserPreferences");
|
|
29
|
+
const shared_1 = require("../shared");
|
|
30
|
+
function register(ctx) {
|
|
31
|
+
const { ts } = ctx;
|
|
32
|
+
return async (uri, range) => {
|
|
33
|
+
const document = ctx.getTextDocument(uri);
|
|
34
|
+
if (!document)
|
|
35
|
+
return;
|
|
36
|
+
const preferences = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
|
|
37
|
+
const fileName = ctx.env.uriToFileName(document.uri);
|
|
38
|
+
const start = document.offsetAt(range.start);
|
|
39
|
+
const end = document.offsetAt(range.end);
|
|
40
|
+
const inlayHints = (0, shared_1.safeCall)(() => 'provideInlayHints' in ctx.typescript.languageService
|
|
41
|
+
? ctx.typescript.languageService.provideInlayHints(fileName, { start, length: end - start }, preferences)
|
|
42
|
+
: []) ?? [];
|
|
43
|
+
return inlayHints.map(inlayHint => {
|
|
44
|
+
const result = vscode.InlayHint.create(document.positionAt(inlayHint.position), inlayHint.text, inlayHint.kind === ts.InlayHintKind.Type ? vscode.InlayHintKind.Type
|
|
45
|
+
: inlayHint.kind === ts.InlayHintKind.Parameter ? vscode.InlayHintKind.Parameter
|
|
46
|
+
: undefined);
|
|
47
|
+
result.paddingLeft = inlayHint.whitespaceBefore;
|
|
48
|
+
result.paddingRight = inlayHint.whitespaceAfter;
|
|
49
|
+
return result;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.register = register;
|
|
54
|
+
//# sourceMappingURL=inlayHints.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SharedContext } from '../types';
|
|
2
|
+
import * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
+
export declare const renameInfoOptions: {
|
|
4
|
+
allowRenameOfImportPath: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function register(ctx: SharedContext): (uri: string, position: vscode.Position) => vscode.Range | undefined | vscode.ResponseError<void>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.register = exports.renameInfoOptions = void 0;
|
|
27
|
+
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
28
|
+
const shared_1 = require("../shared");
|
|
29
|
+
/* typescript-language-features is hardcode true */
|
|
30
|
+
exports.renameInfoOptions = { allowRenameOfImportPath: true };
|
|
31
|
+
function register(ctx) {
|
|
32
|
+
return (uri, position) => {
|
|
33
|
+
const document = ctx.getTextDocument(uri);
|
|
34
|
+
if (!document)
|
|
35
|
+
return;
|
|
36
|
+
const fileName = ctx.env.uriToFileName(document.uri);
|
|
37
|
+
const offset = document.offsetAt(position);
|
|
38
|
+
const renameInfo = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getRenameInfo(fileName, offset, exports.renameInfoOptions));
|
|
39
|
+
if (!renameInfo)
|
|
40
|
+
return;
|
|
41
|
+
if (!renameInfo.canRename) {
|
|
42
|
+
return new vscode.ResponseError(0, renameInfo.localizedErrorMessage);
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
start: document.positionAt(renameInfo.triggerSpan.start),
|
|
46
|
+
end: document.positionAt(renameInfo.triggerSpan.start + renameInfo.triggerSpan.length),
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.register = register;
|
|
51
|
+
//# sourceMappingURL=prepareRename.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = void 0;
|
|
4
|
+
const transforms_1 = require("../utils/transforms");
|
|
5
|
+
const shared_1 = require("../shared");
|
|
6
|
+
function register(ctx) {
|
|
7
|
+
return (uri, position) => {
|
|
8
|
+
const document = ctx.getTextDocument(uri);
|
|
9
|
+
if (!document)
|
|
10
|
+
return [];
|
|
11
|
+
const fileName = ctx.env.uriToFileName(document.uri);
|
|
12
|
+
const offset = document.offsetAt(position);
|
|
13
|
+
const entries = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getReferencesAtPosition(fileName, offset));
|
|
14
|
+
if (!entries)
|
|
15
|
+
return [];
|
|
16
|
+
return (0, transforms_1.entriesToLocations)([...entries], ctx);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.register = register;
|
|
20
|
+
//# sourceMappingURL=references.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
import * as vscode from 'vscode-languageserver-protocol';
|
|
3
|
+
import { SharedContext } from '../types';
|
|
4
|
+
export declare function register(ctx: SharedContext): (uri: string, position: vscode.Position, newName: string) => Promise<vscode.WorkspaceEdit | undefined>;
|
|
5
|
+
export declare function fileTextChangesToWorkspaceEdit(changes: readonly ts.FileTextChanges[], ctx: SharedContext): vscode.WorkspaceEdit;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.fileTextChangesToWorkspaceEdit = exports.register = void 0;
|
|
27
|
+
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
28
|
+
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
|
|
29
|
+
const path_1 = require("path");
|
|
30
|
+
const prepareRename_1 = require("./prepareRename");
|
|
31
|
+
const getFormatCodeSettings_1 = require("../configs/getFormatCodeSettings");
|
|
32
|
+
const getUserPreferences_1 = require("../configs/getUserPreferences");
|
|
33
|
+
const shared_1 = require("../shared");
|
|
34
|
+
function register(ctx) {
|
|
35
|
+
return async (uri, position, newName) => {
|
|
36
|
+
const document = ctx.getTextDocument(uri);
|
|
37
|
+
if (!document)
|
|
38
|
+
return;
|
|
39
|
+
const fileName = ctx.env.uriToFileName(document.uri);
|
|
40
|
+
const offset = document.offsetAt(position);
|
|
41
|
+
const renameInfo = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getRenameInfo(fileName, offset, prepareRename_1.renameInfoOptions));
|
|
42
|
+
if (!renameInfo?.canRename)
|
|
43
|
+
return;
|
|
44
|
+
if (renameInfo.fileToRename) {
|
|
45
|
+
const [formatOptions, preferences] = await Promise.all([
|
|
46
|
+
(0, getFormatCodeSettings_1.getFormatCodeSettings)(ctx, document),
|
|
47
|
+
(0, getUserPreferences_1.getUserPreferences)(ctx, document),
|
|
48
|
+
]);
|
|
49
|
+
return renameFile(renameInfo.fileToRename, newName, formatOptions, preferences);
|
|
50
|
+
}
|
|
51
|
+
const { providePrefixAndSuffixTextForRename } = await (0, getUserPreferences_1.getUserPreferences)(ctx, document);
|
|
52
|
+
const entries = ctx.typescript.languageService.findRenameLocations(fileName, offset, false, false, providePrefixAndSuffixTextForRename);
|
|
53
|
+
if (!entries)
|
|
54
|
+
return;
|
|
55
|
+
const locations = locationsToWorkspaceEdit(newName, entries, ctx);
|
|
56
|
+
return locations;
|
|
57
|
+
};
|
|
58
|
+
function renameFile(fileToRename, newName, formatOptions, preferences) {
|
|
59
|
+
// Make sure we preserve file extension if none provided
|
|
60
|
+
if (!path_1.posix.extname(newName)) {
|
|
61
|
+
newName += path_1.posix.extname(fileToRename);
|
|
62
|
+
}
|
|
63
|
+
const dirname = path_1.posix.dirname(fileToRename);
|
|
64
|
+
const newFilePath = path_1.posix.join(dirname, newName);
|
|
65
|
+
const response = ctx.typescript.languageService.getEditsForFileRename(fileToRename, newFilePath, formatOptions, preferences);
|
|
66
|
+
const edits = fileTextChangesToWorkspaceEdit(response, ctx);
|
|
67
|
+
if (!edits.documentChanges) {
|
|
68
|
+
edits.documentChanges = [];
|
|
69
|
+
}
|
|
70
|
+
edits.documentChanges.push(vscode.RenameFile.create(ctx.env.fileNameToUri(fileToRename), ctx.env.fileNameToUri(newFilePath)));
|
|
71
|
+
return edits;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.register = register;
|
|
75
|
+
function fileTextChangesToWorkspaceEdit(changes, ctx) {
|
|
76
|
+
const workspaceEdit = {};
|
|
77
|
+
for (const change of changes) {
|
|
78
|
+
if (!workspaceEdit.documentChanges) {
|
|
79
|
+
workspaceEdit.documentChanges = [];
|
|
80
|
+
}
|
|
81
|
+
const uri = ctx.env.fileNameToUri(change.fileName);
|
|
82
|
+
let doc = ctx.getTextDocument(uri);
|
|
83
|
+
if (change.isNewFile) {
|
|
84
|
+
workspaceEdit.documentChanges.push(vscode.CreateFile.create(uri));
|
|
85
|
+
doc = vscode_languageserver_textdocument_1.TextDocument.create(uri, 'typescript', 0, '');
|
|
86
|
+
}
|
|
87
|
+
if (!doc)
|
|
88
|
+
continue;
|
|
89
|
+
const docEdit = vscode.TextDocumentEdit.create({
|
|
90
|
+
uri,
|
|
91
|
+
version: null, // fix https://github.com/johnsoncodehk/volar/issues/2025
|
|
92
|
+
}, []);
|
|
93
|
+
for (const textChange of change.textChanges) {
|
|
94
|
+
docEdit.edits.push({
|
|
95
|
+
newText: textChange.newText,
|
|
96
|
+
range: {
|
|
97
|
+
start: doc.positionAt(textChange.span.start),
|
|
98
|
+
end: doc.positionAt(textChange.span.start + textChange.span.length),
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
workspaceEdit.documentChanges.push(docEdit);
|
|
103
|
+
}
|
|
104
|
+
return workspaceEdit;
|
|
105
|
+
}
|
|
106
|
+
exports.fileTextChangesToWorkspaceEdit = fileTextChangesToWorkspaceEdit;
|
|
107
|
+
function locationsToWorkspaceEdit(newText, locations, ctx) {
|
|
108
|
+
const workspaceEdit = {};
|
|
109
|
+
for (const location of locations) {
|
|
110
|
+
if (!workspaceEdit.changes) {
|
|
111
|
+
workspaceEdit.changes = {};
|
|
112
|
+
}
|
|
113
|
+
const uri = ctx.env.fileNameToUri(location.fileName);
|
|
114
|
+
const doc = ctx.getTextDocument(uri);
|
|
115
|
+
if (!doc)
|
|
116
|
+
continue;
|
|
117
|
+
if (!workspaceEdit.changes[uri]) {
|
|
118
|
+
workspaceEdit.changes[uri] = [];
|
|
119
|
+
}
|
|
120
|
+
let _newText = newText;
|
|
121
|
+
if (location.prefixText)
|
|
122
|
+
_newText = location.prefixText + _newText;
|
|
123
|
+
if (location.suffixText)
|
|
124
|
+
_newText = _newText + location.suffixText;
|
|
125
|
+
workspaceEdit.changes[uri].push({
|
|
126
|
+
newText: _newText,
|
|
127
|
+
range: {
|
|
128
|
+
start: doc.positionAt(location.textSpan.start),
|
|
129
|
+
end: doc.positionAt(location.textSpan.start + location.textSpan.length),
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return workspaceEdit;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=rename.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.register = void 0;
|
|
27
|
+
const vscode = __importStar(require("vscode-languageserver-protocol"));
|
|
28
|
+
const shared_1 = require("../shared");
|
|
29
|
+
function register(ctx) {
|
|
30
|
+
return (uri, positions) => {
|
|
31
|
+
const document = ctx.getTextDocument(uri);
|
|
32
|
+
if (!document)
|
|
33
|
+
return [];
|
|
34
|
+
const result = [];
|
|
35
|
+
for (const position of positions) {
|
|
36
|
+
const fileName = ctx.env.uriToFileName(document.uri);
|
|
37
|
+
const offset = document.offsetAt(position);
|
|
38
|
+
const range = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getSmartSelectionRange(fileName, offset));
|
|
39
|
+
if (!range)
|
|
40
|
+
continue;
|
|
41
|
+
result.push(transformSelectionRange(range, document));
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.register = register;
|
|
47
|
+
function transformSelectionRange(range, document) {
|
|
48
|
+
return {
|
|
49
|
+
range: vscode.Range.create(document.positionAt(range.textSpan.start), document.positionAt(range.textSpan.start + range.textSpan.length)),
|
|
50
|
+
parent: range.parent ? transformSelectionRange(range.parent, document) : undefined,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=selectionRanges.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
+
import { SharedContext } from '../types';
|
|
3
|
+
export declare function register(ctx: SharedContext): (uri: string, range: vscode.Range, legend: vscode.SemanticTokensLegend) => [number, number, number, number, number][] | undefined;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = void 0;
|
|
4
|
+
const shared_1 = require("../shared");
|
|
5
|
+
function register(ctx) {
|
|
6
|
+
const { ts } = ctx;
|
|
7
|
+
return (uri, range, legend) => {
|
|
8
|
+
const document = ctx.getTextDocument(uri);
|
|
9
|
+
if (!document)
|
|
10
|
+
return;
|
|
11
|
+
const file = ctx.env.uriToFileName(uri);
|
|
12
|
+
const start = range ? document.offsetAt(range.start) : 0;
|
|
13
|
+
const length = range ? (document.offsetAt(range.end) - start) : document.getText().length;
|
|
14
|
+
if (ctx.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested())
|
|
15
|
+
return;
|
|
16
|
+
const response2 = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getEncodedSyntacticClassifications(file, { start, length }));
|
|
17
|
+
if (!response2)
|
|
18
|
+
return;
|
|
19
|
+
if (ctx.typescript?.languageServiceHost.getCancellationToken?.().isCancellationRequested())
|
|
20
|
+
return;
|
|
21
|
+
const response1 = (0, shared_1.safeCall)(() => ctx.typescript.languageService.getEncodedSemanticClassifications(file, { start, length }, ts.SemanticClassificationFormat.TwentyTwenty));
|
|
22
|
+
if (!response1)
|
|
23
|
+
return;
|
|
24
|
+
let tokenModifiersTable = [];
|
|
25
|
+
tokenModifiersTable[2 /* TokenModifier.async */] = 1 << legend.tokenModifiers.indexOf('async');
|
|
26
|
+
tokenModifiersTable[0 /* TokenModifier.declaration */] = 1 << legend.tokenModifiers.indexOf('declaration');
|
|
27
|
+
tokenModifiersTable[3 /* TokenModifier.readonly */] = 1 << legend.tokenModifiers.indexOf('readonly');
|
|
28
|
+
tokenModifiersTable[1 /* TokenModifier.static */] = 1 << legend.tokenModifiers.indexOf('static');
|
|
29
|
+
tokenModifiersTable[5 /* TokenModifier.local */] = 1 << legend.tokenModifiers.indexOf('local'); // missing in server tokenModifiers
|
|
30
|
+
tokenModifiersTable[4 /* TokenModifier.defaultLibrary */] = 1 << legend.tokenModifiers.indexOf('defaultLibrary');
|
|
31
|
+
tokenModifiersTable = tokenModifiersTable.map(mod => Math.max(mod, 0));
|
|
32
|
+
const tokenSpan = [...response1.spans, ...response2.spans];
|
|
33
|
+
const tokens = [];
|
|
34
|
+
let i = 0;
|
|
35
|
+
while (i < tokenSpan.length) {
|
|
36
|
+
const offset = tokenSpan[i++];
|
|
37
|
+
const length = tokenSpan[i++];
|
|
38
|
+
const tsClassification = tokenSpan[i++];
|
|
39
|
+
let tokenModifiers = 0;
|
|
40
|
+
let tokenType = getTokenTypeFromClassification(tsClassification);
|
|
41
|
+
if (tokenType !== undefined) {
|
|
42
|
+
// it's a classification as returned by the typescript-vscode-sh-plugin
|
|
43
|
+
tokenModifiers = getTokenModifierFromClassification(tsClassification);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// typescript-vscode-sh-plugin is not present
|
|
47
|
+
tokenType = tokenTypeMap[tsClassification];
|
|
48
|
+
if (tokenType === undefined) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const serverToken = tsTokenTypeToServerTokenType(tokenType);
|
|
53
|
+
if (serverToken === undefined) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const serverTokenModifiers = tsTokenModifierToServerTokenModifier(tokenModifiers);
|
|
57
|
+
// we can use the document's range conversion methods because the result is at the same version as the document
|
|
58
|
+
const startPos = document.positionAt(offset);
|
|
59
|
+
const endPos = document.positionAt(offset + length);
|
|
60
|
+
for (let line = startPos.line; line <= endPos.line; line++) {
|
|
61
|
+
const startCharacter = (line === startPos.line ? startPos.character : 0);
|
|
62
|
+
const endCharacter = (line === endPos.line ? endPos.character : docLineLength(document, line));
|
|
63
|
+
tokens.push([line, startCharacter, endCharacter - startCharacter, serverToken, serverTokenModifiers]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return tokens;
|
|
67
|
+
function tsTokenTypeToServerTokenType(tokenType) {
|
|
68
|
+
return legend.tokenTypes.indexOf(tokenTypes[tokenType]);
|
|
69
|
+
}
|
|
70
|
+
function tsTokenModifierToServerTokenModifier(input) {
|
|
71
|
+
let m = 0;
|
|
72
|
+
let i = 0;
|
|
73
|
+
while (input) {
|
|
74
|
+
if (input & 1) {
|
|
75
|
+
m |= tokenModifiersTable[i];
|
|
76
|
+
}
|
|
77
|
+
input = input >> 1;
|
|
78
|
+
i++;
|
|
79
|
+
}
|
|
80
|
+
return m;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
exports.register = register;
|
|
85
|
+
function docLineLength(document, line) {
|
|
86
|
+
const currentLineOffset = document.offsetAt({ line, character: 0 });
|
|
87
|
+
const nextLineOffset = document.offsetAt({ line: line + 1, character: 0 });
|
|
88
|
+
return nextLineOffset - currentLineOffset;
|
|
89
|
+
}
|
|
90
|
+
function getTokenTypeFromClassification(tsClassification) {
|
|
91
|
+
if (tsClassification > 255 /* TokenEncodingConsts.modifierMask */) {
|
|
92
|
+
return (tsClassification >> 8 /* TokenEncodingConsts.typeOffset */) - 1;
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
function getTokenModifierFromClassification(tsClassification) {
|
|
97
|
+
return tsClassification & 255 /* TokenEncodingConsts.modifierMask */;
|
|
98
|
+
}
|
|
99
|
+
const tokenTypes = [];
|
|
100
|
+
tokenTypes[0 /* TokenType.class */] = 'class';
|
|
101
|
+
tokenTypes[1 /* TokenType.enum */] = 'enum';
|
|
102
|
+
tokenTypes[2 /* TokenType.interface */] = 'interface';
|
|
103
|
+
tokenTypes[3 /* TokenType.namespace */] = 'namespace';
|
|
104
|
+
tokenTypes[4 /* TokenType.typeParameter */] = 'typeParameter';
|
|
105
|
+
tokenTypes[5 /* TokenType.type */] = 'type';
|
|
106
|
+
tokenTypes[6 /* TokenType.parameter */] = 'parameter';
|
|
107
|
+
tokenTypes[7 /* TokenType.variable */] = 'variable';
|
|
108
|
+
tokenTypes[8 /* TokenType.enumMember */] = 'enumMember';
|
|
109
|
+
tokenTypes[9 /* TokenType.property */] = 'property';
|
|
110
|
+
tokenTypes[10 /* TokenType.function */] = 'function';
|
|
111
|
+
tokenTypes[11 /* TokenType.method */] = 'method';
|
|
112
|
+
const tokenModifiers = [];
|
|
113
|
+
tokenModifiers[2 /* TokenModifier.async */] = 'async';
|
|
114
|
+
tokenModifiers[0 /* TokenModifier.declaration */] = 'declaration';
|
|
115
|
+
tokenModifiers[3 /* TokenModifier.readonly */] = 'readonly';
|
|
116
|
+
tokenModifiers[1 /* TokenModifier.static */] = 'static';
|
|
117
|
+
tokenModifiers[5 /* TokenModifier.local */] = 'local'; // missing in server tokenModifiers
|
|
118
|
+
tokenModifiers[4 /* TokenModifier.defaultLibrary */] = 'defaultLibrary';
|
|
119
|
+
// mapping for the original ExperimentalProtocol.ClassificationType from TypeScript (only used when plugin is not available)
|
|
120
|
+
const tokenTypeMap = [];
|
|
121
|
+
tokenTypeMap[11 /* ExperimentalProtocol.ClassificationType.className */] = 0 /* TokenType.class */;
|
|
122
|
+
tokenTypeMap[12 /* ExperimentalProtocol.ClassificationType.enumName */] = 1 /* TokenType.enum */;
|
|
123
|
+
tokenTypeMap[13 /* ExperimentalProtocol.ClassificationType.interfaceName */] = 2 /* TokenType.interface */;
|
|
124
|
+
tokenTypeMap[14 /* ExperimentalProtocol.ClassificationType.moduleName */] = 3 /* TokenType.namespace */;
|
|
125
|
+
tokenTypeMap[15 /* ExperimentalProtocol.ClassificationType.typeParameterName */] = 4 /* TokenType.typeParameter */;
|
|
126
|
+
tokenTypeMap[16 /* ExperimentalProtocol.ClassificationType.typeAliasName */] = 5 /* TokenType.type */;
|
|
127
|
+
tokenTypeMap[17 /* ExperimentalProtocol.ClassificationType.parameterName */] = 6 /* TokenType.parameter */;
|
|
128
|
+
//# sourceMappingURL=semanticTokens.js.map
|