@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.
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
16
- let isEnabled = false;
17
- let timeout;
18
- updateEnabledState();
19
- const d1 = vscode.workspace.onDidChangeTextDocument(onDidChangeTextDocument, null);
20
- const d2 = vscode.window.onDidChangeActiveTextEditor(updateEnabledState, null);
21
- return vscode.Disposable.from(d1, d2);
22
- function updateEnabledState() {
23
- isEnabled = false;
24
- let editor = vscode.window.activeTextEditor;
25
- if (!editor) {
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
- function onDidChangeTextDocument({ document, contentChanges, reason }) {
35
- var _a;
36
- if (!isEnabled || contentChanges.length === 0 || reason === vscode.TextDocumentChangeReason.Undo || reason === vscode.TextDocumentChangeReason.Redo) {
37
- return;
38
- }
39
- const activeDocument = (_a = vscode.window.activeTextEditor) === null || _a === void 0 ? void 0 : _a.document;
40
- if (document !== activeDocument) {
41
- return;
42
- }
43
- const lastChange = contentChanges[contentChanges.length - 1];
44
- doAutoInsert(document, lastChange, (document, position, lastChange, isCancel) => __awaiter(this, void 0, void 0, function* () {
45
- for (const client of clients) {
46
- const params = Object.assign(Object.assign({}, client.code2ProtocolConverter.asTextDocumentPositionParams(document, position)), { options: {
47
- lastChange: Object.assign(Object.assign({}, lastChange), { range: client.code2ProtocolConverter.asRange(lastChange.range) }),
48
- } });
49
- if (isCancel())
50
- return;
51
- const result = yield client.sendRequest(language_server_1.AutoInsertRequest.type, params);
52
- if (result !== undefined && result !== null) {
53
- if (typeof result === 'string') {
54
- return result;
55
- }
56
- else {
57
- return client.protocol2CodeConverter.asTextEdit(result);
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
- const version = document.version;
69
- timeout = setTimeout(() => {
70
- const rangeStart = lastChange.range.start;
71
- const position = new vscode.Position(rangeStart.line, rangeStart.character + lastChange.text.length);
72
- provider(document, position, lastChange, () => { var _a; return ((_a = vscode.window.activeTextEditor) === null || _a === void 0 ? void 0 : _a.document.version) !== version; }).then(text => {
73
- if (text && isEnabled) {
74
- const activeEditor = vscode.window.activeTextEditor;
75
- if (activeEditor) {
76
- const activeDocument = activeEditor.document;
77
- if (document === activeDocument && activeDocument.version === version) {
78
- if (typeof text === 'string') {
79
- const selections = activeEditor.selections;
80
- if (selections.length && selections.some(s => s.active.isEqual(position))) {
81
- activeEditor.insertSnippet(new vscode.SnippetString(text), selections.map(s => s.active));
82
- }
83
- else {
84
- activeEditor.insertSnippet(new vscode.SnippetString(text), position);
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.newText), text.range);
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
- timeout = undefined;
95
- }, 100);
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 __awaiter(this, void 0, void 0, function* () {
18
- return vscode.commands.registerCommand(cmd, (uri) => __awaiter(this, void 0, void 0, function* () {
19
- // https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/fileReferences.ts
20
- yield vscode.window.withProgress({
21
- location: vscode.ProgressLocation.Window,
22
- title: localize('progress.title', "Finding file references")
23
- }, (_progress) => __awaiter(this, void 0, void 0, function* () {
24
- var _a;
25
- if (!uri) {
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
- const locations = response.map(loc => client.protocol2CodeConverter.asLocation(loc));
36
- const config = vscode.workspace.getConfiguration('references');
37
- const existingSetting = config.inspect('preferredLocation');
38
- yield config.update('preferredLocation', 'view');
39
- try {
40
- yield vscode.commands.executeCommand('editor.action.showReferences', uri, new vscode.Position(0, 0), locations);
41
- }
42
- finally {
43
- yield config.update('preferredLocation', (_a = existingSetting === null || existingSetting === void 0 ? void 0 : existingSetting.workspaceFolderValue) !== null && _a !== void 0 ? _a : existingSetting === null || existingSetting === void 0 ? void 0 : existingSetting.workspaceValue);
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 __awaiter(this, void 0, void 0, function* () {
16
- return vscode.commands.registerCommand(cmd, () => {
17
- if (vscode.window.activeTextEditor) {
18
- for (const client of clients) {
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 __awaiter(this, void 0, void 0, function* () {
16
- return vscode.commands.registerCommand(cmd, () => __awaiter(this, void 0, void 0, function* () {
17
- for (const client of clients) {
18
- yield client.sendNotification(language_server_1.ReportStats.type);
19
- client.outputChannel.show();
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
- return __awaiter(this, void 0, void 0, function* () {
17
- const subscriptions = [];
18
- addHandle();
19
- subscriptions.push(client.onDidChangeState(() => {
20
- if (client.state === vscode_languageclient_1.State.Running) {
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
- return vscode.Disposable.from(...subscriptions);
28
- function addHandle() {
29
- subscriptions.push(client.onRequest(language_server_1.FsReadFileRequest.type, (uri) => __awaiter(this, void 0, void 0, function* () {
30
- if (cdn && uri.startsWith(cdn) && context.globalState.get(uri) === false) {
31
- return;
32
- }
33
- const uri2 = client.protocol2CodeConverter.asUri(uri);
34
- try {
35
- return yield vscode.workspace.fs.readFile(uri2);
36
- }
37
- catch (err) {
38
- if (cdn && uri.startsWith(cdn)) {
39
- context.globalState.update(uri, false);
40
- }
41
- }
42
- })));
43
- subscriptions.push(client.onRequest(language_server_1.FsReadDirectoryRequest.type, (uri) => __awaiter(this, void 0, void 0, function* () {
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
- catch (_a) {
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
- return __awaiter(this, void 0, void 0, function* () {
17
- const subscriptions = [];
18
- addHandle();
19
- subscriptions.push(client.onDidChangeState(() => {
20
- if (client.state === vscode_languageclient_1.State.Running) {
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
- return __awaiter(this, void 0, void 0, function* () {
42
- class MappingDataHoverProvider {
43
- provideHover(document, position, _token) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- const maps = virtualUriToSourceMap.get(document.uri.toString());
46
- if (!maps)
47
- return;
48
- const data = [];
49
- for (const [sourceUri, _, map] of maps) {
50
- const source = map.toSourceOffset(document.offsetAt(position));
51
- if (source) {
52
- data.push({
53
- uri: sourceUri,
54
- mapping: source,
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
- const subscriptions = [];
72
- subscriptions.push(vscode.languages.registerHoverProvider({ scheme }, new MappingDataHoverProvider()));
73
- const sourceUriToVirtualUris = new Map();
74
- const virtualUriToSourceEditor = new Map();
75
- const virtualUriToSourceMap = new Map();
76
- const docChangeEvent = new vscode.EventEmitter();
77
- const virtualDocuments = new Map();
78
- let updateVirtualDocument;
79
- let updateDecorationsTimeout;
80
- subscriptions.push(vscode.window.onDidChangeActiveTextEditor(updateDecorations));
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
- subscriptions.push(vscode.workspace.registerTextDocumentContentProvider(scheme, {
95
- onDidChange: docChangeEvent.event,
96
- provideTextDocumentContent(uri) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- const fileName = uri.with({ scheme: 'file' }).fsPath;
99
- const requestEditor = virtualUriToSourceEditor.get(uri.toString());
100
- if (requestEditor) {
101
- const virtual = yield client.sendRequest(language_server_1.GetVirtualFileRequest.type, { sourceFileUri: requestEditor.document.uri.toString(), virtualFileName: fileName });
102
- virtualUriToSourceMap.set(uri.toString(), []);
103
- Object.entries(virtual.mappings).forEach(([sourceUri, mappings]) => {
104
- var _a, _b;
105
- const sourceEditor = vscode.window.visibleTextEditors.find(editor => editor.document.uri.toString() === sourceUri);
106
- if (sourceEditor) {
107
- (_a = virtualUriToSourceMap.get(uri.toString())) === null || _a === void 0 ? void 0 : _a.push([
108
- sourceEditor.document.uri.toString(),
109
- sourceEditor.document.version,
110
- new source_map_1.SourceMap(mappings),
111
- ]);
112
- if (!sourceUriToVirtualUris.has(sourceUri)) {
113
- sourceUriToVirtualUris.set(sourceUri, new Set());
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
- virtualDocuments.set(uri.toString(), vscode_languageclient_1.TextDocument.create('', '', 0, virtual.content));
119
- clearTimeout(updateDecorationsTimeout);
120
- updateDecorationsTimeout = setTimeout(updateDecorations, 100);
121
- return virtual.content;
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
- function getGeneratedPosition(virtualUri, offset) {
197
- const document = virtualDocuments.get(virtualUri);
198
- const position = document.positionAt(offset);
199
- return new vscode.Position(position.line, position.character);
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
- return __awaiter(this, void 0, void 0, function* () {
18
- const subscriptions = [];
19
- const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
20
- statusBar.command = cmd;
21
- subscriptions.push({ dispose: () => statusBar.dispose() });
22
- subscriptions.push(vscode.commands.registerCommand(cmd, onCommand));
23
- vscode.workspace.onDidChangeConfiguration(onDidChangeConfiguration, undefined, subscriptions);
24
- vscode.window.onDidChangeActiveTextEditor(updateStatusBar, undefined, subscriptions);
25
- updateStatusBar();
26
- return vscode.Disposable.from(...subscriptions);
27
- function onCommand() {
28
- var _a, _b, _c, _d;
29
- return __awaiter(this, void 0, void 0, function* () {
30
- const tsdk = getTsdk(context);
31
- const configTsdkPath = getConfigTsdkPath();
32
- const vscodeTsdk = getVScodeTsdk();
33
- const select = yield (0, common_1.quickPick)([
34
- {
35
- useVSCodeTsdk: {
36
- label: (!tsdk.isWorkspacePath ? '• ' : '') + "Use VS Code's Version",
37
- description: vscodeTsdk.version,
38
- detail: vscodeTsdk.isWeb ? vscodeTsdk.path.replace('/node_modules/', cdn) : undefined,
39
- },
40
- useConfigWorkspaceTsdk: configTsdkPath && !vscodeTsdk.isWeb ? {
41
- label: (tsdk.isWorkspacePath ? '• ' : '') + 'Use Workspace Version',
42
- description: (_b = yield getTsVersion((_a = resolveWorkspaceTsdk(configTsdkPath)) !== null && _a !== void 0 ? _a : '/')) !== null && _b !== void 0 ? _b : 'Could not load the TypeScript version at this path',
43
- detail: configTsdkPath,
44
- } : undefined,
45
- useDefaultWorkspaceTsdk: configTsdkPath !== defaultTsdkPath && !vscodeTsdk.isWeb ? {
46
- label: (tsdk.isWorkspacePath ? '• ' : '') + 'Use Workspace Version',
47
- description: (_d = yield getTsVersion((_c = resolveWorkspaceTsdk(defaultTsdkPath)) !== null && _c !== void 0 ? _c : '/')) !== null && _d !== void 0 ? _d : 'Could not load the TypeScript version at this path',
48
- detail: defaultTsdkPath,
49
- } : undefined,
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
- ...(disableTakeOverMode ? [] : [{
52
- takeover: {
53
- label: 'What is Takeover Mode?',
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
- function onDidChangeConfiguration(e) {
76
- if (e.affectsConfiguration('typescript.tsdk') && isUseWorkspaceTsdk(context)) {
77
- reloadServers();
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
- function updateStatusBar() {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- if (!vscode.window.activeTextEditor
83
- || !shouldStatusBarShow(vscode.window.activeTextEditor.document)) {
84
- statusBar.hide();
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
- function reloadServers() {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- const tsPaths = getTsdk(context);
97
- const newInitOptions = Object.assign(Object.assign({}, client.clientOptions.initializationOptions), { typescript: tsPaths });
98
- client.clientOptions.initializationOptions = newInitOptions;
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 (_b) { }
116
+ catch { }
133
117
  }
134
- const workspaceFolderFsPaths = ((_a = vscode.workspace.workspaceFolders) !== null && _a !== void 0 ? _a : []).map(folder => folder.uri.fsPath);
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 (_c) { }
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
- return __awaiter(this, void 0, void 0, function* () {
179
- const p = libPath.toString().split('/');
180
- const p2 = p.slice(0, -1);
181
- const modulePath = p2.join('/');
182
- const filePath = modulePath + '/package.json';
183
- const contents = yield readFile(filePath);
184
- if (contents === undefined) {
185
- return;
186
- }
187
- let desc = null;
188
- try {
189
- desc = JSON.parse(contents);
190
- }
191
- catch (err) {
192
- return;
193
- }
194
- if (!desc || !desc.version) {
195
- return;
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
- return __awaiter(this, void 0, void 0, function* () {
202
- try {
203
- const data = yield vscode.workspace.fs.readFile(vscode.Uri.file(path));
204
- return new TextDecoder('utf8').decode(data);
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
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
17
- const subscriptions = [];
18
- const statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right);
19
- let currentTsconfigUri;
20
- updateStatusBar();
21
- vscode.window.onDidChangeActiveTextEditor(updateStatusBar, undefined, subscriptions);
22
- subscriptions.push(vscode.commands.registerCommand(cmd, () => __awaiter(this, void 0, void 0, function* () {
23
- if (currentTsconfigUri) {
24
- const document = yield vscode.workspace.openTextDocument(currentTsconfigUri);
25
- yield vscode.window.showTextDocument(document);
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 __awaiter(this, void 0, void 0, function* () {
16
- return vscode.commands.registerCommand(cmd, () => {
17
- if (vscode.window.activeTextEditor) {
18
- client.sendNotification(language_server_1.WriteVirtualFilesNotification.type, client.code2ProtocolConverter.asTextDocumentIdentifier(vscode.window.activeTextEditor.document));
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.0",
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.0",
17
- "@volar/source-map": "1.4.0-alpha.0",
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": "2607410cae341cf802b446062d446ad497be2057"
29
+ "gitHead": "41ea915b137aea284e2bf5edd98a788ce21b779c"
30
30
  }