@volar/vscode 1.4.0-alpha.0 → 1.4.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/out/features/autoInsertion.js +77 -83
- package/out/features/fileReferences.js +27 -39
- package/out/features/reloadProject.js +6 -17
- package/out/features/serverStatus.js +6 -17
- package/out/features/serverSys.js +38 -49
- package/out/features/showReferences.js +16 -27
- package/out/features/showVirtualFiles.js +138 -154
- package/out/features/tsVersion.js +105 -125
- package/out/features/tsconfig.js +30 -43
- package/out/features/writeVirtualFiles.js +5 -16
- package/package.json +4 -4
|
@@ -1,100 +1,94 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.activate = void 0;
|
|
12
3
|
const vscode = require("vscode");
|
|
13
4
|
const language_server_1 = require("@volar/language-server");
|
|
14
|
-
function activate(clients, active) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
let document = editor.document;
|
|
29
|
-
if (!active(document)) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
isEnabled = true;
|
|
5
|
+
async function activate(clients, active) {
|
|
6
|
+
let isEnabled = false;
|
|
7
|
+
let timeout;
|
|
8
|
+
updateEnabledState();
|
|
9
|
+
const d1 = vscode.workspace.onDidChangeTextDocument(onDidChangeTextDocument, null);
|
|
10
|
+
const d2 = vscode.window.onDidChangeActiveTextEditor(updateEnabledState, null);
|
|
11
|
+
return vscode.Disposable.from(d1, d2);
|
|
12
|
+
function updateEnabledState() {
|
|
13
|
+
isEnabled = false;
|
|
14
|
+
let editor = vscode.window.activeTextEditor;
|
|
15
|
+
if (!editor) {
|
|
16
|
+
return;
|
|
33
17
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
18
|
+
let document = editor.document;
|
|
19
|
+
if (!active(document)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
isEnabled = true;
|
|
23
|
+
}
|
|
24
|
+
function onDidChangeTextDocument({ document, contentChanges, reason }) {
|
|
25
|
+
if (!isEnabled || contentChanges.length === 0 || reason === vscode.TextDocumentChangeReason.Undo || reason === vscode.TextDocumentChangeReason.Redo) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const activeDocument = vscode.window.activeTextEditor?.document;
|
|
29
|
+
if (document !== activeDocument) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const lastChange = contentChanges[contentChanges.length - 1];
|
|
33
|
+
doAutoInsert(document, lastChange, async (document, position, lastChange, isCancel) => {
|
|
34
|
+
for (const client of clients) {
|
|
35
|
+
const params = {
|
|
36
|
+
...client.code2ProtocolConverter.asTextDocumentPositionParams(document, position),
|
|
37
|
+
options: {
|
|
38
|
+
lastChange: {
|
|
39
|
+
...lastChange,
|
|
40
|
+
range: client.code2ProtocolConverter.asRange(lastChange.range),
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
if (isCancel())
|
|
45
|
+
return;
|
|
46
|
+
const result = await client.sendRequest(language_server_1.AutoInsertRequest.type, params);
|
|
47
|
+
if (result !== undefined && result !== null) {
|
|
48
|
+
if (typeof result === 'string') {
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return client.protocol2CodeConverter.asTextEdit(result);
|
|
59
53
|
}
|
|
60
54
|
}
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
function doAutoInsert(document, lastChange, provider) {
|
|
64
|
-
if (timeout) {
|
|
65
|
-
clearTimeout(timeout);
|
|
66
|
-
timeout = undefined;
|
|
67
55
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function doAutoInsert(document, lastChange, provider) {
|
|
59
|
+
if (timeout) {
|
|
60
|
+
clearTimeout(timeout);
|
|
61
|
+
timeout = undefined;
|
|
62
|
+
}
|
|
63
|
+
const version = document.version;
|
|
64
|
+
timeout = setTimeout(() => {
|
|
65
|
+
const rangeStart = lastChange.range.start;
|
|
66
|
+
const position = new vscode.Position(rangeStart.line, rangeStart.character + lastChange.text.length);
|
|
67
|
+
provider(document, position, lastChange, () => vscode.window.activeTextEditor?.document.version !== version).then(text => {
|
|
68
|
+
if (text && isEnabled) {
|
|
69
|
+
const activeEditor = vscode.window.activeTextEditor;
|
|
70
|
+
if (activeEditor) {
|
|
71
|
+
const activeDocument = activeEditor.document;
|
|
72
|
+
if (document === activeDocument && activeDocument.version === version) {
|
|
73
|
+
if (typeof text === 'string') {
|
|
74
|
+
const selections = activeEditor.selections;
|
|
75
|
+
if (selections.length && selections.some(s => s.active.isEqual(position))) {
|
|
76
|
+
activeEditor.insertSnippet(new vscode.SnippetString(text), selections.map(s => s.active));
|
|
86
77
|
}
|
|
87
78
|
else {
|
|
88
|
-
activeEditor.insertSnippet(new vscode.SnippetString(text
|
|
79
|
+
activeEditor.insertSnippet(new vscode.SnippetString(text), position);
|
|
89
80
|
}
|
|
90
81
|
}
|
|
82
|
+
else {
|
|
83
|
+
activeEditor.insertSnippet(new vscode.SnippetString(text.newText), text.range);
|
|
84
|
+
}
|
|
91
85
|
}
|
|
92
86
|
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
timeout = undefined;
|
|
90
|
+
}, 100);
|
|
91
|
+
}
|
|
98
92
|
}
|
|
99
93
|
exports.activate = activate;
|
|
100
94
|
//# sourceMappingURL=autoInsertion.js.map
|
|
@@ -1,49 +1,37 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.activate = void 0;
|
|
12
3
|
const vscode = require("vscode");
|
|
13
4
|
const nls = require("vscode-nls");
|
|
14
5
|
const language_server_1 = require("@volar/language-server");
|
|
15
6
|
const localize = nls.loadMessageBundle();
|
|
16
|
-
function activate(cmd, client) {
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (!
|
|
26
|
-
const editor = vscode.window.activeTextEditor;
|
|
27
|
-
if (!editor)
|
|
28
|
-
return;
|
|
29
|
-
uri = editor.document.uri;
|
|
30
|
-
}
|
|
31
|
-
const response = yield client.sendRequest(language_server_1.FindFileReferenceRequest.type, { textDocument: { uri: uri.toString() } });
|
|
32
|
-
if (!response) {
|
|
7
|
+
async function activate(cmd, client) {
|
|
8
|
+
return vscode.commands.registerCommand(cmd, async (uri) => {
|
|
9
|
+
// https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/fileReferences.ts
|
|
10
|
+
await vscode.window.withProgress({
|
|
11
|
+
location: vscode.ProgressLocation.Window,
|
|
12
|
+
title: localize('progress.title', "Finding file references")
|
|
13
|
+
}, async (_progress) => {
|
|
14
|
+
if (!uri) {
|
|
15
|
+
const editor = vscode.window.activeTextEditor;
|
|
16
|
+
if (!editor)
|
|
33
17
|
return;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
18
|
+
uri = editor.document.uri;
|
|
19
|
+
}
|
|
20
|
+
const response = await client.sendRequest(language_server_1.FindFileReferenceRequest.type, { textDocument: { uri: uri.toString() } });
|
|
21
|
+
if (!response) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const locations = response.map(loc => client.protocol2CodeConverter.asLocation(loc));
|
|
25
|
+
const config = vscode.workspace.getConfiguration('references');
|
|
26
|
+
const existingSetting = config.inspect('preferredLocation');
|
|
27
|
+
await config.update('preferredLocation', 'view');
|
|
28
|
+
try {
|
|
29
|
+
await vscode.commands.executeCommand('editor.action.showReferences', uri, new vscode.Position(0, 0), locations);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
await config.update('preferredLocation', existingSetting?.workspaceFolderValue ?? existingSetting?.workspaceValue);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
47
35
|
});
|
|
48
36
|
}
|
|
49
37
|
exports.activate = activate;
|
|
@@ -1,25 +1,14 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.activate = void 0;
|
|
12
3
|
const vscode = require("vscode");
|
|
13
4
|
const language_server_1 = require("@volar/language-server");
|
|
14
|
-
function activate(cmd, clients) {
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
client.sendNotification(language_server_1.ReloadProjectNotification.type, client.code2ProtocolConverter.asTextDocumentIdentifier(vscode.window.activeTextEditor.document));
|
|
20
|
-
}
|
|
5
|
+
async function activate(cmd, clients) {
|
|
6
|
+
return vscode.commands.registerCommand(cmd, () => {
|
|
7
|
+
if (vscode.window.activeTextEditor) {
|
|
8
|
+
for (const client of clients) {
|
|
9
|
+
client.sendNotification(language_server_1.ReloadProjectNotification.type, client.code2ProtocolConverter.asTextDocumentIdentifier(vscode.window.activeTextEditor.document));
|
|
21
10
|
}
|
|
22
|
-
}
|
|
11
|
+
}
|
|
23
12
|
});
|
|
24
13
|
}
|
|
25
14
|
exports.activate = activate;
|
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.activate = void 0;
|
|
12
3
|
const vscode = require("vscode");
|
|
13
4
|
const language_server_1 = require("@volar/language-server");
|
|
14
|
-
function activate(cmd, clients) {
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
}));
|
|
5
|
+
async function activate(cmd, clients) {
|
|
6
|
+
return vscode.commands.registerCommand(cmd, async () => {
|
|
7
|
+
for (const client of clients) {
|
|
8
|
+
await client.sendNotification(language_server_1.ReportStats.type);
|
|
9
|
+
client.outputChannel.show();
|
|
10
|
+
}
|
|
22
11
|
});
|
|
23
12
|
}
|
|
24
13
|
exports.activate = activate;
|
|
@@ -1,61 +1,50 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.activate = void 0;
|
|
12
3
|
const vscode = require("vscode");
|
|
13
4
|
const vscode_languageclient_1 = require("vscode-languageclient");
|
|
14
5
|
const language_server_1 = require("@volar/language-server");
|
|
15
|
-
function activate(context, client, cdn) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
addHandle();
|
|
22
|
-
}
|
|
23
|
-
}));
|
|
24
|
-
if (cdn) {
|
|
25
|
-
console.log('skips:', context.globalState.keys().filter(key => key.startsWith(cdn)).length);
|
|
6
|
+
async function activate(context, client, cdn) {
|
|
7
|
+
const subscriptions = [];
|
|
8
|
+
addHandle();
|
|
9
|
+
subscriptions.push(client.onDidChangeState(() => {
|
|
10
|
+
if (client.state === vscode_languageclient_1.State.Running) {
|
|
11
|
+
addHandle();
|
|
26
12
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
if (cdn && uri.startsWith(cdn)) {
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
const uri2 = client.protocol2CodeConverter.asUri(uri);
|
|
49
|
-
let data = yield vscode.workspace.fs.readDirectory(uri2);
|
|
50
|
-
data = data.filter(([name]) => !name.startsWith('.'));
|
|
51
|
-
return data;
|
|
13
|
+
}));
|
|
14
|
+
if (cdn) {
|
|
15
|
+
console.log('skips:', context.globalState.keys().filter(key => key.startsWith(cdn)).length);
|
|
16
|
+
}
|
|
17
|
+
return vscode.Disposable.from(...subscriptions);
|
|
18
|
+
function addHandle() {
|
|
19
|
+
subscriptions.push(client.onRequest(language_server_1.FsReadFileRequest.type, async (uri) => {
|
|
20
|
+
if (cdn && uri.startsWith(cdn) && context.globalState.get(uri) === false) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const uri2 = client.protocol2CodeConverter.asUri(uri);
|
|
24
|
+
try {
|
|
25
|
+
return await vscode.workspace.fs.readFile(uri2);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
if (cdn && uri.startsWith(cdn)) {
|
|
29
|
+
context.globalState.update(uri, false);
|
|
52
30
|
}
|
|
53
|
-
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
subscriptions.push(client.onRequest(language_server_1.FsReadDirectoryRequest.type, async (uri) => {
|
|
34
|
+
try {
|
|
35
|
+
if (cdn && uri.startsWith(cdn)) {
|
|
54
36
|
return [];
|
|
55
37
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
38
|
+
const uri2 = client.protocol2CodeConverter.asUri(uri);
|
|
39
|
+
let data = await vscode.workspace.fs.readDirectory(uri2);
|
|
40
|
+
data = data.filter(([name]) => !name.startsWith('.'));
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
59
48
|
}
|
|
60
49
|
exports.activate = activate;
|
|
61
50
|
//# sourceMappingURL=serverSys.js.map
|
|
@@ -1,36 +1,25 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.activate = void 0;
|
|
12
3
|
const vscode = require("vscode");
|
|
13
4
|
const vscode_languageclient_1 = require("vscode-languageclient");
|
|
14
5
|
const language_server_1 = require("@volar/language-server");
|
|
15
|
-
function activate(client) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
addHandle();
|
|
22
|
-
}
|
|
23
|
-
}));
|
|
24
|
-
return vscode.Disposable.from(...subscriptions);
|
|
25
|
-
function addHandle() {
|
|
26
|
-
subscriptions.push(client.onNotification(language_server_1.ShowReferencesNotification.type, params => {
|
|
27
|
-
const uri = params.textDocument.uri;
|
|
28
|
-
const pos = params.position;
|
|
29
|
-
const refs = params.references;
|
|
30
|
-
vscode.commands.executeCommand('editor.action.showReferences', vscode.Uri.parse(uri), new vscode.Position(pos.line, pos.character), refs.map(ref => new vscode.Location(vscode.Uri.parse(ref.uri), new vscode.Range(ref.range.start.line, ref.range.start.character, ref.range.end.line, ref.range.end.character))));
|
|
31
|
-
}));
|
|
6
|
+
async function activate(client) {
|
|
7
|
+
const subscriptions = [];
|
|
8
|
+
addHandle();
|
|
9
|
+
subscriptions.push(client.onDidChangeState(() => {
|
|
10
|
+
if (client.state === vscode_languageclient_1.State.Running) {
|
|
11
|
+
addHandle();
|
|
32
12
|
}
|
|
33
|
-
});
|
|
13
|
+
}));
|
|
14
|
+
return vscode.Disposable.from(...subscriptions);
|
|
15
|
+
function addHandle() {
|
|
16
|
+
subscriptions.push(client.onNotification(language_server_1.ShowReferencesNotification.type, params => {
|
|
17
|
+
const uri = params.textDocument.uri;
|
|
18
|
+
const pos = params.position;
|
|
19
|
+
const refs = params.references;
|
|
20
|
+
vscode.commands.executeCommand('editor.action.showReferences', vscode.Uri.parse(uri), new vscode.Position(pos.line, pos.character), refs.map(ref => new vscode.Location(vscode.Uri.parse(ref.uri), new vscode.Range(ref.range.start.line, ref.range.start.character, ref.range.end.line, ref.range.end.character))));
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
34
23
|
}
|
|
35
24
|
exports.activate = activate;
|
|
36
25
|
//# sourceMappingURL=showReferences.js.map
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.activate = void 0;
|
|
12
3
|
const vscode = require("vscode");
|
|
@@ -37,168 +28,161 @@ const mappingSelectionDecorationType = vscode.window.createTextEditorDecorationT
|
|
|
37
28
|
backgroundColor: 'darkblue'
|
|
38
29
|
}
|
|
39
30
|
});
|
|
40
|
-
function activate(cmd, client) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
31
|
+
async function activate(cmd, client) {
|
|
32
|
+
class MappingDataHoverProvider {
|
|
33
|
+
async provideHover(document, position, _token) {
|
|
34
|
+
const maps = virtualUriToSourceMap.get(document.uri.toString());
|
|
35
|
+
if (!maps)
|
|
36
|
+
return;
|
|
37
|
+
const data = [];
|
|
38
|
+
for (const [sourceUri, _, map] of maps) {
|
|
39
|
+
const source = map.toSourceOffset(document.offsetAt(position));
|
|
40
|
+
if (source) {
|
|
41
|
+
data.push({
|
|
42
|
+
uri: sourceUri,
|
|
43
|
+
mapping: source,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (data.length === 0)
|
|
48
|
+
return;
|
|
49
|
+
return new vscode.Hover(data.map((data) => [
|
|
50
|
+
data.uri,
|
|
51
|
+
'',
|
|
52
|
+
'',
|
|
53
|
+
'```json',
|
|
54
|
+
JSON.stringify(data.mapping, null, 2),
|
|
55
|
+
'```',
|
|
56
|
+
].join('\n')));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const subscriptions = [];
|
|
60
|
+
subscriptions.push(vscode.languages.registerHoverProvider({ scheme }, new MappingDataHoverProvider()));
|
|
61
|
+
const sourceUriToVirtualUris = new Map();
|
|
62
|
+
const virtualUriToSourceEditor = new Map();
|
|
63
|
+
const virtualUriToSourceMap = new Map();
|
|
64
|
+
const docChangeEvent = new vscode.EventEmitter();
|
|
65
|
+
const virtualDocuments = new Map();
|
|
66
|
+
let updateVirtualDocument;
|
|
67
|
+
let updateDecorationsTimeout;
|
|
68
|
+
subscriptions.push(vscode.window.onDidChangeActiveTextEditor(updateDecorations));
|
|
69
|
+
subscriptions.push(vscode.window.onDidChangeTextEditorSelection(updateDecorations));
|
|
70
|
+
subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(updateDecorations));
|
|
71
|
+
subscriptions.push(vscode.workspace.onDidChangeTextDocument(e => {
|
|
72
|
+
if (sourceUriToVirtualUris.has(e.document.uri.toString())) {
|
|
73
|
+
const virtualUris = sourceUriToVirtualUris.get(e.document.uri.toString());
|
|
74
|
+
clearTimeout(updateVirtualDocument);
|
|
75
|
+
updateVirtualDocument = setTimeout(() => {
|
|
76
|
+
virtualUris?.forEach(uri => {
|
|
77
|
+
docChangeEvent.fire(vscode.Uri.parse(uri));
|
|
78
|
+
});
|
|
79
|
+
}, 100);
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
82
|
+
subscriptions.push(vscode.workspace.registerTextDocumentContentProvider(scheme, {
|
|
83
|
+
onDidChange: docChangeEvent.event,
|
|
84
|
+
async provideTextDocumentContent(uri) {
|
|
85
|
+
const fileName = uri.with({ scheme: 'file' }).fsPath;
|
|
86
|
+
const requestEditor = virtualUriToSourceEditor.get(uri.toString());
|
|
87
|
+
if (requestEditor) {
|
|
88
|
+
const virtual = await client.sendRequest(language_server_1.GetVirtualFileRequest.type, { sourceFileUri: requestEditor.document.uri.toString(), virtualFileName: fileName });
|
|
89
|
+
virtualUriToSourceMap.set(uri.toString(), []);
|
|
90
|
+
Object.entries(virtual.mappings).forEach(([sourceUri, mappings]) => {
|
|
91
|
+
const sourceEditor = vscode.window.visibleTextEditors.find(editor => editor.document.uri.toString() === sourceUri);
|
|
92
|
+
if (sourceEditor) {
|
|
93
|
+
virtualUriToSourceMap.get(uri.toString())?.push([
|
|
94
|
+
sourceEditor.document.uri.toString(),
|
|
95
|
+
sourceEditor.document.version,
|
|
96
|
+
new source_map_1.SourceMap(mappings),
|
|
97
|
+
]);
|
|
98
|
+
if (!sourceUriToVirtualUris.has(sourceUri)) {
|
|
99
|
+
sourceUriToVirtualUris.set(sourceUri, new Set());
|
|
56
100
|
}
|
|
101
|
+
sourceUriToVirtualUris.get(sourceUri)?.add(uri.toString());
|
|
57
102
|
}
|
|
58
|
-
if (data.length === 0)
|
|
59
|
-
return;
|
|
60
|
-
return new vscode.Hover(data.map((data) => [
|
|
61
|
-
data.uri,
|
|
62
|
-
'',
|
|
63
|
-
'',
|
|
64
|
-
'```json',
|
|
65
|
-
JSON.stringify(data.mapping, null, 2),
|
|
66
|
-
'```',
|
|
67
|
-
].join('\n')));
|
|
68
103
|
});
|
|
104
|
+
virtualDocuments.set(uri.toString(), vscode_languageclient_1.TextDocument.create('', '', 0, virtual.content));
|
|
105
|
+
clearTimeout(updateDecorationsTimeout);
|
|
106
|
+
updateDecorationsTimeout = setTimeout(updateDecorations, 100);
|
|
107
|
+
return virtual.content;
|
|
69
108
|
}
|
|
70
109
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
subscriptions.push(vscode.window.onDidChangeTextEditorSelection(updateDecorations));
|
|
82
|
-
subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(updateDecorations));
|
|
83
|
-
subscriptions.push(vscode.workspace.onDidChangeTextDocument(e => {
|
|
84
|
-
if (sourceUriToVirtualUris.has(e.document.uri.toString())) {
|
|
85
|
-
const virtualUris = sourceUriToVirtualUris.get(e.document.uri.toString());
|
|
86
|
-
clearTimeout(updateVirtualDocument);
|
|
87
|
-
updateVirtualDocument = setTimeout(() => {
|
|
88
|
-
virtualUris === null || virtualUris === void 0 ? void 0 : virtualUris.forEach(uri => {
|
|
89
|
-
docChangeEvent.fire(vscode.Uri.parse(uri));
|
|
90
|
-
});
|
|
91
|
-
}, 100);
|
|
110
|
+
}));
|
|
111
|
+
subscriptions.push(vscode.commands.registerCommand(cmd, async () => {
|
|
112
|
+
const sourceEditor = vscode.window.activeTextEditor;
|
|
113
|
+
if (sourceEditor) {
|
|
114
|
+
const fileNames = await client.sendRequest(language_server_1.GetVirtualFileNamesRequest.type, client.code2ProtocolConverter.asTextDocumentIdentifier(sourceEditor.document));
|
|
115
|
+
const uris = fileNames.map(fileName => vscode.Uri.file(fileName).with({ scheme }));
|
|
116
|
+
sourceUriToVirtualUris.set(sourceEditor.document.uri.toString(), new Set(uris.map(uri => uri.toString())));
|
|
117
|
+
for (const uri of uris) {
|
|
118
|
+
virtualUriToSourceEditor.set(uri.toString(), sourceEditor);
|
|
119
|
+
vscode.window.showTextDocument(uri, { viewColumn: vscode.ViewColumn.Two, preview: false });
|
|
92
120
|
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
121
|
+
}
|
|
122
|
+
}));
|
|
123
|
+
return vscode.Disposable.from(...subscriptions);
|
|
124
|
+
function updateDecorations() {
|
|
125
|
+
for (const [virtualUri, sources] of virtualUriToSourceMap) {
|
|
126
|
+
const virtualEditor = vscode.window.visibleTextEditors.find(editor => editor.document.uri.toString() === virtualUri);
|
|
127
|
+
let virtualRanges1 = [];
|
|
128
|
+
let virtualRanges2 = [];
|
|
129
|
+
if (virtualEditor) {
|
|
130
|
+
for (const [sourceUri, sourceVersion, map] of sources) {
|
|
131
|
+
const sourceEditor = vscode.window.visibleTextEditors.find(editor => editor.document.uri.toString() === sourceUri);
|
|
132
|
+
if (sourceEditor && sourceEditor.document.version === sourceVersion) {
|
|
133
|
+
const mappingDecorationRanges = map.mappings.map(mapping => new vscode.Range(sourceEditor.document.positionAt(mapping.sourceRange[0]), sourceEditor.document.positionAt(mapping.sourceRange[1])));
|
|
134
|
+
sourceEditor.setDecorations(mappingDecorationType, mappingDecorationRanges);
|
|
135
|
+
virtualRanges1 = virtualRanges1.concat(map.mappings.map(mapping => new vscode.Range(getGeneratedPosition(virtualUri, mapping.generatedRange[0]), getGeneratedPosition(virtualUri, mapping.generatedRange[1]))));
|
|
136
|
+
/**
|
|
137
|
+
* selection
|
|
138
|
+
*/
|
|
139
|
+
if (vscode.window.activeTextEditor) {
|
|
140
|
+
const selection = vscode.window.activeTextEditor.selection;
|
|
141
|
+
const startOffset = vscode.window.activeTextEditor.document.offsetAt(selection.start);
|
|
142
|
+
sourceEditor.setDecorations(mappingSelectionDecorationType, []);
|
|
143
|
+
if (vscode.window.activeTextEditor === sourceEditor) {
|
|
144
|
+
const matchVirtualRanges = [...map.toGeneratedOffsets(startOffset)];
|
|
145
|
+
sourceEditor.setDecorations(mappingSelectionDecorationType, matchVirtualRanges.map(mapped => new vscode.Range(sourceEditor.document.positionAt(mapped[1].sourceRange[0]), sourceEditor.document.positionAt(mapped[1].sourceRange[1]))));
|
|
146
|
+
virtualRanges2 = virtualRanges2.concat(matchVirtualRanges.map(mapped => new vscode.Range(getGeneratedPosition(virtualUri, mapped[1].generatedRange[0]), getGeneratedPosition(virtualUri, mapped[1].generatedRange[1]))));
|
|
147
|
+
const mapped = matchVirtualRanges.sort((a, b) => a[1].generatedRange[0] - b[1].generatedRange[0])[0];
|
|
148
|
+
if (mapped) {
|
|
149
|
+
virtualEditor.revealRange(new vscode.Range(getGeneratedPosition(virtualUri, mapped[1].generatedRange[0]), getGeneratedPosition(virtualUri, mapped[1].generatedRange[1])));
|
|
114
150
|
}
|
|
115
|
-
(_b = sourceUriToVirtualUris.get(sourceUri)) === null || _b === void 0 ? void 0 : _b.add(uri.toString());
|
|
116
151
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
}));
|
|
126
|
-
subscriptions.push(vscode.commands.registerCommand(cmd, () => __awaiter(this, void 0, void 0, function* () {
|
|
127
|
-
const sourceEditor = vscode.window.activeTextEditor;
|
|
128
|
-
if (sourceEditor) {
|
|
129
|
-
const fileNames = yield client.sendRequest(language_server_1.GetVirtualFileNamesRequest.type, client.code2ProtocolConverter.asTextDocumentIdentifier(sourceEditor.document));
|
|
130
|
-
const uris = fileNames.map(fileName => vscode.Uri.file(fileName).with({ scheme }));
|
|
131
|
-
sourceUriToVirtualUris.set(sourceEditor.document.uri.toString(), new Set(uris.map(uri => uri.toString())));
|
|
132
|
-
for (const uri of uris) {
|
|
133
|
-
virtualUriToSourceEditor.set(uri.toString(), sourceEditor);
|
|
134
|
-
vscode.window.showTextDocument(uri, { viewColumn: vscode.ViewColumn.Two, preview: false });
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
})));
|
|
138
|
-
return vscode.Disposable.from(...subscriptions);
|
|
139
|
-
function updateDecorations() {
|
|
140
|
-
for (const [virtualUri, sources] of virtualUriToSourceMap) {
|
|
141
|
-
const virtualEditor = vscode.window.visibleTextEditors.find(editor => editor.document.uri.toString() === virtualUri);
|
|
142
|
-
let virtualRanges1 = [];
|
|
143
|
-
let virtualRanges2 = [];
|
|
144
|
-
if (virtualEditor) {
|
|
145
|
-
for (const [sourceUri, sourceVersion, map] of sources) {
|
|
146
|
-
const sourceEditor = vscode.window.visibleTextEditors.find(editor => editor.document.uri.toString() === sourceUri);
|
|
147
|
-
if (sourceEditor && sourceEditor.document.version === sourceVersion) {
|
|
148
|
-
const mappingDecorationRanges = map.mappings.map(mapping => new vscode.Range(sourceEditor.document.positionAt(mapping.sourceRange[0]), sourceEditor.document.positionAt(mapping.sourceRange[1])));
|
|
149
|
-
sourceEditor.setDecorations(mappingDecorationType, mappingDecorationRanges);
|
|
150
|
-
virtualRanges1 = virtualRanges1.concat(map.mappings.map(mapping => new vscode.Range(getGeneratedPosition(virtualUri, mapping.generatedRange[0]), getGeneratedPosition(virtualUri, mapping.generatedRange[1]))));
|
|
151
|
-
/**
|
|
152
|
-
* selection
|
|
153
|
-
*/
|
|
154
|
-
if (vscode.window.activeTextEditor) {
|
|
155
|
-
const selection = vscode.window.activeTextEditor.selection;
|
|
156
|
-
const startOffset = vscode.window.activeTextEditor.document.offsetAt(selection.start);
|
|
157
|
-
sourceEditor.setDecorations(mappingSelectionDecorationType, []);
|
|
158
|
-
if (vscode.window.activeTextEditor === sourceEditor) {
|
|
159
|
-
const matchVirtualRanges = [...map.toGeneratedOffsets(startOffset)];
|
|
160
|
-
sourceEditor.setDecorations(mappingSelectionDecorationType, matchVirtualRanges.map(mapped => new vscode.Range(sourceEditor.document.positionAt(mapped[1].sourceRange[0]), sourceEditor.document.positionAt(mapped[1].sourceRange[1]))));
|
|
161
|
-
virtualRanges2 = virtualRanges2.concat(matchVirtualRanges.map(mapped => new vscode.Range(getGeneratedPosition(virtualUri, mapped[1].generatedRange[0]), getGeneratedPosition(virtualUri, mapped[1].generatedRange[1]))));
|
|
162
|
-
const mapped = matchVirtualRanges.sort((a, b) => a[1].generatedRange[0] - b[1].generatedRange[0])[0];
|
|
163
|
-
if (mapped) {
|
|
164
|
-
virtualEditor.revealRange(new vscode.Range(getGeneratedPosition(virtualUri, mapped[1].generatedRange[0]), getGeneratedPosition(virtualUri, mapped[1].generatedRange[1])));
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
else if (vscode.window.activeTextEditor === virtualEditor) {
|
|
168
|
-
const matchSourceRanges = [...map.toSourceOffsets(startOffset)];
|
|
169
|
-
sourceEditor.setDecorations(mappingSelectionDecorationType, matchSourceRanges.map(mapped => new vscode.Range(sourceEditor.document.positionAt(mapped[1].sourceRange[0]), sourceEditor.document.positionAt(mapped[1].sourceRange[1]))));
|
|
170
|
-
virtualRanges2 = virtualRanges2.concat(matchSourceRanges.map(mapped => new vscode.Range(getGeneratedPosition(virtualUri, mapped[1].generatedRange[0]), getGeneratedPosition(virtualUri, mapped[1].generatedRange[1]))));
|
|
171
|
-
const mapped = matchSourceRanges.sort((a, b) => a[1].sourceRange[0] - b[1].sourceRange[0])[0];
|
|
172
|
-
if (mapped) {
|
|
173
|
-
sourceEditor.revealRange(new vscode.Range(sourceEditor.document.positionAt(mapped[1].sourceRange[0]), sourceEditor.document.positionAt(mapped[1].sourceRange[1])));
|
|
174
|
-
}
|
|
152
|
+
else if (vscode.window.activeTextEditor === virtualEditor) {
|
|
153
|
+
const matchSourceRanges = [...map.toSourceOffsets(startOffset)];
|
|
154
|
+
sourceEditor.setDecorations(mappingSelectionDecorationType, matchSourceRanges.map(mapped => new vscode.Range(sourceEditor.document.positionAt(mapped[1].sourceRange[0]), sourceEditor.document.positionAt(mapped[1].sourceRange[1]))));
|
|
155
|
+
virtualRanges2 = virtualRanges2.concat(matchSourceRanges.map(mapped => new vscode.Range(getGeneratedPosition(virtualUri, mapped[1].generatedRange[0]), getGeneratedPosition(virtualUri, mapped[1].generatedRange[1]))));
|
|
156
|
+
const mapped = matchSourceRanges.sort((a, b) => a[1].sourceRange[0] - b[1].sourceRange[0])[0];
|
|
157
|
+
if (mapped) {
|
|
158
|
+
sourceEditor.revealRange(new vscode.Range(sourceEditor.document.positionAt(mapped[1].sourceRange[0]), sourceEditor.document.positionAt(mapped[1].sourceRange[1])));
|
|
175
159
|
}
|
|
176
160
|
}
|
|
177
|
-
else {
|
|
178
|
-
sourceEditor.setDecorations(mappingSelectionDecorationType, []);
|
|
179
|
-
}
|
|
180
161
|
}
|
|
181
|
-
|
|
182
|
-
virtualEditor.setDecorations(mappingDecorationType, virtualRanges1);
|
|
183
|
-
virtualEditor.setDecorations(mappingSelectionDecorationType, virtualRanges2);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
for (const [sourceUri] of sources) {
|
|
187
|
-
const sourceEditor = vscode.window.visibleTextEditors.find(editor => editor.document.uri.toString() === sourceUri);
|
|
188
|
-
if (sourceEditor) {
|
|
189
|
-
sourceEditor.setDecorations(mappingDecorationType, []);
|
|
162
|
+
else {
|
|
190
163
|
sourceEditor.setDecorations(mappingSelectionDecorationType, []);
|
|
191
164
|
}
|
|
192
165
|
}
|
|
193
166
|
}
|
|
167
|
+
virtualEditor.setDecorations(mappingDecorationType, virtualRanges1);
|
|
168
|
+
virtualEditor.setDecorations(mappingSelectionDecorationType, virtualRanges2);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
for (const [sourceUri] of sources) {
|
|
172
|
+
const sourceEditor = vscode.window.visibleTextEditors.find(editor => editor.document.uri.toString() === sourceUri);
|
|
173
|
+
if (sourceEditor) {
|
|
174
|
+
sourceEditor.setDecorations(mappingDecorationType, []);
|
|
175
|
+
sourceEditor.setDecorations(mappingSelectionDecorationType, []);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
194
178
|
}
|
|
195
179
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
180
|
+
}
|
|
181
|
+
function getGeneratedPosition(virtualUri, offset) {
|
|
182
|
+
const document = virtualDocuments.get(virtualUri);
|
|
183
|
+
const position = document.positionAt(offset);
|
|
184
|
+
return new vscode.Position(position.line, position.character);
|
|
185
|
+
}
|
|
202
186
|
}
|
|
203
187
|
exports.activate = activate;
|
|
204
188
|
//# sourceMappingURL=showVirtualFiles.js.map
|
|
@@ -1,105 +1,90 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.getTsdk = exports.activate = void 0;
|
|
12
3
|
const path = require("typesafe-path");
|
|
13
4
|
const vscode = require("vscode");
|
|
14
5
|
const common_1 = require("../common");
|
|
15
6
|
const defaultTsdkPath = 'node_modules/typescript/lib';
|
|
16
|
-
function activate(cmd, context, client, shouldStatusBarShow, resolveStatusText, disableTakeOverMode, cdn = 'https://unpkg.com/') {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
7
|
+
async function activate(cmd, context, client, shouldStatusBarShow, resolveStatusText, disableTakeOverMode, cdn = 'https://unpkg.com/') {
|
|
8
|
+
const subscriptions = [];
|
|
9
|
+
const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
|
|
10
|
+
statusBar.command = cmd;
|
|
11
|
+
subscriptions.push({ dispose: () => statusBar.dispose() });
|
|
12
|
+
subscriptions.push(vscode.commands.registerCommand(cmd, onCommand));
|
|
13
|
+
vscode.workspace.onDidChangeConfiguration(onDidChangeConfiguration, undefined, subscriptions);
|
|
14
|
+
vscode.window.onDidChangeActiveTextEditor(updateStatusBar, undefined, subscriptions);
|
|
15
|
+
updateStatusBar();
|
|
16
|
+
return vscode.Disposable.from(...subscriptions);
|
|
17
|
+
async function onCommand() {
|
|
18
|
+
const tsdk = getTsdk(context);
|
|
19
|
+
const configTsdkPath = getConfigTsdkPath();
|
|
20
|
+
const vscodeTsdk = getVScodeTsdk();
|
|
21
|
+
const select = await (0, common_1.quickPick)([
|
|
22
|
+
{
|
|
23
|
+
useVSCodeTsdk: {
|
|
24
|
+
label: (!tsdk.isWorkspacePath ? '• ' : '') + "Use VS Code's Version",
|
|
25
|
+
description: vscodeTsdk.version,
|
|
26
|
+
detail: vscodeTsdk.isWeb ? vscodeTsdk.path.replace('/node_modules/', cdn) : undefined,
|
|
27
|
+
},
|
|
28
|
+
useConfigWorkspaceTsdk: configTsdkPath && !vscodeTsdk.isWeb ? {
|
|
29
|
+
label: (tsdk.isWorkspacePath ? '• ' : '') + 'Use Workspace Version',
|
|
30
|
+
description: await getTsVersion(resolveWorkspaceTsdk(configTsdkPath) ?? '/') ?? 'Could not load the TypeScript version at this path',
|
|
31
|
+
detail: configTsdkPath,
|
|
32
|
+
} : undefined,
|
|
33
|
+
useDefaultWorkspaceTsdk: configTsdkPath !== defaultTsdkPath && !vscodeTsdk.isWeb ? {
|
|
34
|
+
label: (tsdk.isWorkspacePath ? '• ' : '') + 'Use Workspace Version',
|
|
35
|
+
description: await getTsVersion(resolveWorkspaceTsdk(defaultTsdkPath) ?? '/') ?? 'Could not load the TypeScript version at this path',
|
|
36
|
+
detail: defaultTsdkPath,
|
|
37
|
+
} : undefined,
|
|
38
|
+
},
|
|
39
|
+
...(disableTakeOverMode ? [] : [{
|
|
40
|
+
takeover: {
|
|
41
|
+
label: 'What is Takeover Mode?',
|
|
50
42
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}])
|
|
56
|
-
]);
|
|
57
|
-
if (select === undefined) {
|
|
58
|
-
return; // cancel
|
|
59
|
-
}
|
|
60
|
-
if (select === 'takeover') {
|
|
61
|
-
vscode.env.openExternal(vscode.Uri.parse('https://vuejs.org/guide/typescript/overview.html#volar-takeover-mode'));
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (select === 'useDefaultWorkspaceTsdk') {
|
|
65
|
-
yield vscode.workspace.getConfiguration('typescript').update('tsdk', defaultTsdkPath);
|
|
66
|
-
}
|
|
67
|
-
const useWorkspaceTsdk = select === 'useConfigWorkspaceTsdk' || select === 'useDefaultWorkspaceTsdk';
|
|
68
|
-
if (useWorkspaceTsdk !== isUseWorkspaceTsdk(context)) {
|
|
69
|
-
context.workspaceState.update('typescript.useWorkspaceTsdk', useWorkspaceTsdk);
|
|
70
|
-
reloadServers();
|
|
71
|
-
}
|
|
72
|
-
updateStatusBar();
|
|
73
|
-
});
|
|
43
|
+
}])
|
|
44
|
+
]);
|
|
45
|
+
if (select === undefined) {
|
|
46
|
+
return; // cancel
|
|
74
47
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
48
|
+
if (select === 'takeover') {
|
|
49
|
+
vscode.env.openExternal(vscode.Uri.parse('https://vuejs.org/guide/typescript/overview.html#volar-takeover-mode'));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (select === 'useDefaultWorkspaceTsdk') {
|
|
53
|
+
await vscode.workspace.getConfiguration('typescript').update('tsdk', defaultTsdkPath);
|
|
54
|
+
}
|
|
55
|
+
const useWorkspaceTsdk = select === 'useConfigWorkspaceTsdk' || select === 'useDefaultWorkspaceTsdk';
|
|
56
|
+
if (useWorkspaceTsdk !== isUseWorkspaceTsdk(context)) {
|
|
57
|
+
context.workspaceState.update('typescript.useWorkspaceTsdk', useWorkspaceTsdk);
|
|
58
|
+
reloadServers();
|
|
59
|
+
}
|
|
60
|
+
updateStatusBar();
|
|
61
|
+
}
|
|
62
|
+
function onDidChangeConfiguration(e) {
|
|
63
|
+
if (e.affectsConfiguration('typescript.tsdk') && isUseWorkspaceTsdk(context)) {
|
|
64
|
+
reloadServers();
|
|
79
65
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
const tsVersion = getTsdk(context).version;
|
|
88
|
-
statusBar.text = tsVersion !== null && tsVersion !== void 0 ? tsVersion : 'x.x.x';
|
|
89
|
-
statusBar.text = resolveStatusText(statusBar.text);
|
|
90
|
-
statusBar.show();
|
|
91
|
-
}
|
|
92
|
-
});
|
|
66
|
+
}
|
|
67
|
+
async function updateStatusBar() {
|
|
68
|
+
if (!vscode.window.activeTextEditor
|
|
69
|
+
|| !shouldStatusBarShow(vscode.window.activeTextEditor.document)) {
|
|
70
|
+
statusBar.hide();
|
|
93
71
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
vscode.commands.executeCommand('volar.action.restartServer');
|
|
100
|
-
});
|
|
72
|
+
else {
|
|
73
|
+
const tsVersion = getTsdk(context).version;
|
|
74
|
+
statusBar.text = tsVersion ?? 'x.x.x';
|
|
75
|
+
statusBar.text = resolveStatusText(statusBar.text);
|
|
76
|
+
statusBar.show();
|
|
101
77
|
}
|
|
102
|
-
}
|
|
78
|
+
}
|
|
79
|
+
async function reloadServers() {
|
|
80
|
+
const tsPaths = getTsdk(context);
|
|
81
|
+
const newInitOptions = {
|
|
82
|
+
...client.clientOptions.initializationOptions,
|
|
83
|
+
typescript: tsPaths,
|
|
84
|
+
};
|
|
85
|
+
client.clientOptions.initializationOptions = newInitOptions;
|
|
86
|
+
vscode.commands.executeCommand('volar.action.restartServer');
|
|
87
|
+
}
|
|
103
88
|
}
|
|
104
89
|
exports.activate = activate;
|
|
105
90
|
function getTsdk(context) {
|
|
@@ -122,16 +107,15 @@ function getTsdk(context) {
|
|
|
122
107
|
}
|
|
123
108
|
exports.getTsdk = getTsdk;
|
|
124
109
|
function resolveWorkspaceTsdk(tsdk) {
|
|
125
|
-
var _a;
|
|
126
110
|
if (path.isAbsolute(tsdk)) {
|
|
127
111
|
try {
|
|
128
112
|
if (require.resolve('./typescript.js', { paths: [tsdk] })) {
|
|
129
113
|
return tsdk;
|
|
130
114
|
}
|
|
131
115
|
}
|
|
132
|
-
catch
|
|
116
|
+
catch { }
|
|
133
117
|
}
|
|
134
|
-
const workspaceFolderFsPaths = (
|
|
118
|
+
const workspaceFolderFsPaths = (vscode.workspace.workspaceFolders ?? []).map(folder => folder.uri.fsPath);
|
|
135
119
|
for (const folder of workspaceFolderFsPaths) {
|
|
136
120
|
const _path = path.join(folder, tsdk);
|
|
137
121
|
try {
|
|
@@ -139,7 +123,7 @@ function resolveWorkspaceTsdk(tsdk) {
|
|
|
139
123
|
return _path;
|
|
140
124
|
}
|
|
141
125
|
}
|
|
142
|
-
catch
|
|
126
|
+
catch { }
|
|
143
127
|
}
|
|
144
128
|
}
|
|
145
129
|
function getVScodeTsdk() {
|
|
@@ -174,36 +158,32 @@ function getConfigTsdkPath() {
|
|
|
174
158
|
function isUseWorkspaceTsdk(context) {
|
|
175
159
|
return context.workspaceState.get('typescript.useWorkspaceTsdk', false);
|
|
176
160
|
}
|
|
177
|
-
function getTsVersion(libPath) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return desc.version;
|
|
198
|
-
});
|
|
161
|
+
async function getTsVersion(libPath) {
|
|
162
|
+
const p = libPath.toString().split('/');
|
|
163
|
+
const p2 = p.slice(0, -1);
|
|
164
|
+
const modulePath = p2.join('/');
|
|
165
|
+
const filePath = modulePath + '/package.json';
|
|
166
|
+
const contents = await readFile(filePath);
|
|
167
|
+
if (contents === undefined) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
let desc = null;
|
|
171
|
+
try {
|
|
172
|
+
desc = JSON.parse(contents);
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (!desc || !desc.version) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
return desc.version;
|
|
199
181
|
}
|
|
200
|
-
function readFile(path) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
catch (_a) { }
|
|
207
|
-
});
|
|
182
|
+
async function readFile(path) {
|
|
183
|
+
try {
|
|
184
|
+
const data = await vscode.workspace.fs.readFile(vscode.Uri.file(path));
|
|
185
|
+
return new TextDecoder('utf8').decode(data);
|
|
186
|
+
}
|
|
187
|
+
catch { }
|
|
208
188
|
}
|
|
209
189
|
//# sourceMappingURL=tsVersion.js.map
|
package/out/features/tsconfig.js
CHANGED
|
@@ -1,53 +1,40 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.activate = void 0;
|
|
12
3
|
const vscode = require("vscode");
|
|
13
4
|
const language_server_1 = require("@volar/language-server");
|
|
14
5
|
const path = require("typesafe-path");
|
|
15
|
-
function activate(cmd, client, shouldStatusBarShow) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
async function activate(cmd, client, shouldStatusBarShow) {
|
|
7
|
+
const subscriptions = [];
|
|
8
|
+
const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
|
|
9
|
+
let currentTsconfigUri;
|
|
10
|
+
updateStatusBar();
|
|
11
|
+
vscode.window.onDidChangeActiveTextEditor(updateStatusBar, undefined, subscriptions);
|
|
12
|
+
subscriptions.push(vscode.commands.registerCommand(cmd, async () => {
|
|
13
|
+
if (currentTsconfigUri) {
|
|
14
|
+
const document = await vscode.workspace.openTextDocument(currentTsconfigUri);
|
|
15
|
+
await vscode.window.showTextDocument(document);
|
|
16
|
+
}
|
|
17
|
+
}));
|
|
18
|
+
subscriptions.push(...subscriptions);
|
|
19
|
+
async function updateStatusBar() {
|
|
20
|
+
if (!vscode.window.activeTextEditor
|
|
21
|
+
|| !shouldStatusBarShow(vscode.window.activeTextEditor.document)) {
|
|
22
|
+
statusBar.hide();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const tsconfig = await client.sendRequest(language_server_1.GetMatchTsConfigRequest.type, client.code2ProtocolConverter.asTextDocumentIdentifier(vscode.window.activeTextEditor.document));
|
|
26
|
+
if (tsconfig?.uri) {
|
|
27
|
+
currentTsconfigUri = vscode.Uri.parse(tsconfig.uri);
|
|
28
|
+
statusBar.text = path.relative((vscode.workspace.rootPath || '/'), currentTsconfigUri.fsPath);
|
|
29
|
+
statusBar.command = cmd;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
statusBar.text = 'No tsconfig';
|
|
33
|
+
statusBar.command = undefined;
|
|
26
34
|
}
|
|
27
|
-
|
|
28
|
-
subscriptions.push(...subscriptions);
|
|
29
|
-
function updateStatusBar() {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
if (!vscode.window.activeTextEditor
|
|
32
|
-
|| !shouldStatusBarShow(vscode.window.activeTextEditor.document)) {
|
|
33
|
-
statusBar.hide();
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
const tsconfig = yield client.sendRequest(language_server_1.GetMatchTsConfigRequest.type, client.code2ProtocolConverter.asTextDocumentIdentifier(vscode.window.activeTextEditor.document));
|
|
37
|
-
if (tsconfig === null || tsconfig === void 0 ? void 0 : tsconfig.uri) {
|
|
38
|
-
currentTsconfigUri = vscode.Uri.parse(tsconfig.uri);
|
|
39
|
-
statusBar.text = path.relative((vscode.workspace.rootPath || '/'), currentTsconfigUri.fsPath);
|
|
40
|
-
statusBar.command = cmd;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
statusBar.text = 'No tsconfig';
|
|
44
|
-
statusBar.command = undefined;
|
|
45
|
-
}
|
|
46
|
-
statusBar.show();
|
|
47
|
-
}
|
|
48
|
-
});
|
|
35
|
+
statusBar.show();
|
|
49
36
|
}
|
|
50
|
-
}
|
|
37
|
+
}
|
|
51
38
|
}
|
|
52
39
|
exports.activate = activate;
|
|
53
40
|
//# sourceMappingURL=tsconfig.js.map
|
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
2
|
exports.activate = void 0;
|
|
12
3
|
const vscode = require("vscode");
|
|
13
4
|
const language_server_1 = require("@volar/language-server");
|
|
14
|
-
function activate(cmd, client) {
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
});
|
|
5
|
+
async function activate(cmd, client) {
|
|
6
|
+
return vscode.commands.registerCommand(cmd, () => {
|
|
7
|
+
if (vscode.window.activeTextEditor) {
|
|
8
|
+
client.sendNotification(language_server_1.WriteVirtualFilesNotification.type, client.code2ProtocolConverter.asTextDocumentIdentifier(vscode.window.activeTextEditor.document));
|
|
9
|
+
}
|
|
21
10
|
});
|
|
22
11
|
}
|
|
23
12
|
exports.activate = activate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/vscode",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.1",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"directory": "packages/vscode"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-server": "1.4.0-alpha.
|
|
17
|
-
"@volar/source-map": "1.4.0-alpha.
|
|
16
|
+
"@volar/language-server": "1.4.0-alpha.1",
|
|
17
|
+
"@volar/source-map": "1.4.0-alpha.1",
|
|
18
18
|
"typesafe-path": "^0.2.2",
|
|
19
19
|
"vscode-nls": "^5.2.0"
|
|
20
20
|
},
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"@types/vscode": "*",
|
|
27
27
|
"vscode-languageclient": "*"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "41ea915b137aea284e2bf5edd98a788ce21b779c"
|
|
30
30
|
}
|