Skip to content

Commit 4eddf60

Browse files
committed
更新语言规则
1 parent 4102093 commit 4eddf60

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

client/src/extension.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,30 @@ import * as addonManager from './addon_manager/registration';
55

66
import luadoc from "../3rd/vscode-lua-doc/extension.js";
77

8+
interface LuaDocContext extends vscode.ExtensionContext {
9+
ViewType: string;
10+
OpenCommand: string;
11+
}
12+
813
export function activate(context: vscode.ExtensionContext) {
914
languageserver.activate(context);
1015

11-
const luaDocContext = {
12-
...context,
16+
const luaDocContext: LuaDocContext = {
17+
asAbsolutePath: context.asAbsolutePath,
18+
environmentVariableCollection: context.environmentVariableCollection,
19+
extensionUri: context.extensionUri,
20+
globalState: context.globalState,
21+
storagePath: context.storagePath,
22+
subscriptions: context.subscriptions,
23+
workspaceState: context.workspaceState,
24+
extensionMode: context.extensionMode,
25+
globalStorageUri: context.globalStorageUri,
26+
logUri: context.logUri,
27+
logPath: context.logPath,
28+
globalStoragePath: context.globalStoragePath,
29+
extension: context.extension,
30+
secrets: context.secrets,
31+
storageUri: context.storageUri,
1332
extensionPath: context.extensionPath + '/client/3rd/vscode-lua-doc',
1433
ViewType: 'lua-doc',
1534
OpenCommand: 'extension.lua.doc',
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as vscode from 'vscode';
2+
3+
export const luaConfiguration: vscode.LanguageConfiguration = {
4+
autoClosingPairs: [
5+
{ open: "{", close: "}" },
6+
{ open: "[", close: "]" },
7+
{ open: "(", close: ")" },
8+
{ open: "'", close: "'", notIn: [vscode.SyntaxTokenType.String] },
9+
{ open: '"', close: '"', notIn: [vscode.SyntaxTokenType.String] },
10+
{ open: "[=", close: "=]" },
11+
{ open: "[==", close: "==]" },
12+
{ open: "[===", close: "===]" },
13+
{ open: "[====", close: "====]" },
14+
{ open: "[=====", close: "=====]" },
15+
],
16+
onEnterRules: [
17+
{
18+
beforeText: /\b(\)|then|do|else)\b\s*$/,
19+
afterText: /^\s*end\b/,
20+
action: {
21+
indentAction: vscode.IndentAction.IndentOutdent,
22+
}
23+
},
24+
{
25+
beforeText: /\b(repeat)\b\s*$/,
26+
afterText: /^\s*until\b/,
27+
action: {
28+
indentAction: vscode.IndentAction.IndentOutdent,
29+
}
30+
},
31+
]
32+
};

client/src/languageserver.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from 'path';
22
import * as os from 'os';
33
import * as fs from 'fs';
44
import * as vscode from 'vscode';
5+
import { luaConfiguration } from './languageConfiguration';
56
import {
67
workspace as Workspace,
78
ExtensionContext,
@@ -109,7 +110,13 @@ class LuaClient extends Disposable {
109110
private context: ExtensionContext,
110111
private documentSelector: DocumentSelector
111112
) {
112-
super(() => this.dispose());
113+
super(() => {
114+
for (const disposable of this.disposables) {
115+
disposable.dispose();
116+
}
117+
});
118+
119+
this.disposables.push(vscode.languages.setLanguageConfiguration('lua', luaConfiguration));
113120
}
114121

115122
async start() {
@@ -245,9 +252,7 @@ class LuaClient extends Disposable {
245252

246253
async stop() {
247254
this.client?.stop();
248-
for (const disposable of this.disposables) {
249-
disposable.dispose();
250-
}
255+
this.dispose();
251256
}
252257

253258
statusBar() {

0 commit comments

Comments
 (0)