@volar/vscode 2.0.1 → 2.0.3

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.
@@ -7,9 +7,11 @@ function activate(selector, client) {
7
7
  let isEnabled = false;
8
8
  let timeout;
9
9
  updateEnabledState();
10
- const d1 = vscode.workspace.onDidChangeTextDocument(onDidChangeTextDocument, null);
11
- const d2 = vscode.window.onDidChangeActiveTextEditor(updateEnabledState, null);
12
- return vscode.Disposable.from(d1, d2);
10
+ const disposables = [
11
+ vscode.workspace.onDidChangeTextDocument(onDidChangeTextDocument, null),
12
+ vscode.window.onDidChangeActiveTextEditor(updateEnabledState, null),
13
+ ];
14
+ return vscode.Disposable.from(...disposables);
13
15
  function updateEnabledState() {
14
16
  isEnabled = false;
15
17
  let editor = vscode.window.activeTextEditor;
@@ -30,8 +32,27 @@ function activate(selector, client) {
30
32
  if (document !== activeDocument) {
31
33
  return;
32
34
  }
35
+ if (timeout) {
36
+ clearTimeout(timeout);
37
+ }
33
38
  const lastChange = contentChanges[contentChanges.length - 1];
34
- doAutoInsert(document, lastChange, async (document, position, lastChange, isCancel) => {
39
+ doAutoInsert(document, lastChange);
40
+ }
41
+ function doAutoInsert(document, lastChange) {
42
+ if (timeout) {
43
+ clearTimeout(timeout);
44
+ timeout = undefined;
45
+ }
46
+ const version = document.version;
47
+ timeout = setTimeout(async () => {
48
+ timeout = undefined;
49
+ const isCancel = () => document !== vscode.window.activeTextEditor?.document
50
+ || vscode.window.activeTextEditor?.document.version !== version;
51
+ if (isCancel()) {
52
+ return;
53
+ }
54
+ const rangeStart = lastChange.range.start;
55
+ const position = new vscode.Position(rangeStart.line, rangeStart.character + lastChange.text.length);
35
56
  const params = {
36
57
  ...client.code2ProtocolConverter.asTextDocumentPositionParams(document, position),
37
58
  lastChange: {
@@ -39,52 +60,27 @@ function activate(selector, client) {
39
60
  range: client.code2ProtocolConverter.asRange(lastChange.range),
40
61
  },
41
62
  };
42
- if (isCancel()) {
43
- return;
44
- }
45
- const result = await client.sendRequest(protocol_1.AutoInsertRequest.type, params);
46
- if (result !== undefined && result !== null) {
47
- if (typeof result === 'string') {
48
- return result;
63
+ const insertion = await client.sendRequest(protocol_1.AutoInsertRequest.type, params);
64
+ const activeEditor = vscode.window.activeTextEditor;
65
+ if (insertion !== undefined
66
+ && insertion !== null
67
+ && isEnabled
68
+ && !isCancel()
69
+ && activeEditor) {
70
+ if (typeof insertion === 'string') {
71
+ const selections = activeEditor.selections;
72
+ if (selections.length && selections.some(s => s.active.isEqual(position))) {
73
+ activeEditor.insertSnippet(new vscode.SnippetString(insertion), selections.map(s => s.active));
74
+ }
75
+ else {
76
+ activeEditor.insertSnippet(new vscode.SnippetString(insertion), position);
77
+ }
49
78
  }
50
79
  else {
51
- return client.protocol2CodeConverter.asTextEdit(result);
80
+ const edit = client.protocol2CodeConverter.asTextEdit(insertion);
81
+ activeEditor.insertSnippet(new vscode.SnippetString(edit.newText), edit.range);
52
82
  }
53
83
  }
54
- });
55
- }
56
- function doAutoInsert(document, lastChange, provider) {
57
- if (timeout) {
58
- clearTimeout(timeout);
59
- timeout = undefined;
60
- }
61
- const version = document.version;
62
- timeout = setTimeout(() => {
63
- const rangeStart = lastChange.range.start;
64
- const position = new vscode.Position(rangeStart.line, rangeStart.character + lastChange.text.length);
65
- provider(document, position, lastChange, () => vscode.window.activeTextEditor?.document.version !== version).then(text => {
66
- if (text && isEnabled) {
67
- const activeEditor = vscode.window.activeTextEditor;
68
- if (activeEditor) {
69
- const activeDocument = activeEditor.document;
70
- if (document === activeDocument && activeDocument.version === version) {
71
- if (typeof text === 'string') {
72
- const selections = activeEditor.selections;
73
- if (selections.length && selections.some(s => s.active.isEqual(position))) {
74
- activeEditor.insertSnippet(new vscode.SnippetString(text), selections.map(s => s.active));
75
- }
76
- else {
77
- activeEditor.insertSnippet(new vscode.SnippetString(text), position);
78
- }
79
- }
80
- else {
81
- activeEditor.insertSnippet(new vscode.SnippetString(text.newText), text.range);
82
- }
83
- }
84
- }
85
- }
86
- });
87
- timeout = undefined;
88
84
  }, 100);
89
85
  }
90
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/vscode",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/vscode"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-server": "2.0.1",
15
+ "@volar/language-server": "2.0.3",
16
16
  "path-browserify": "^1.0.1",
17
17
  "vscode-languageclient": "^9.0.1",
18
18
  "vscode-nls": "^5.2.0"
@@ -22,5 +22,5 @@
22
22
  "@types/path-browserify": "latest",
23
23
  "@types/vscode": "^1.82.0"
24
24
  },
25
- "gitHead": "b1fbf6eed522624ccccfb17a8999edfbc1d8d9bb"
25
+ "gitHead": "d8a6dc056d37779ff6486f545f45bc57b22c02e4"
26
26
  }