Skip to content

Commit dca35c3

Browse files
committed
reset,取消子模块更改
1 parent 63fa1f4 commit dca35c3

File tree

4 files changed

+218
-7
lines changed

4 files changed

+218
-7
lines changed

client/out/ConfigWatcher.js

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/out/languageserver.js

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/ConfigWatcher.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import path = require('path');
2+
import * as vscode from 'vscode';
3+
4+
export enum UpdateType {
5+
Created = 1,
6+
Changed = 2,
7+
Deleted = 3
8+
}
9+
10+
export interface IConfigSource {
11+
uri: string;
12+
path: string;
13+
workspace: string;
14+
}
15+
16+
export interface IConfigUpdate {
17+
type: UpdateType;
18+
source: IConfigSource;
19+
}
20+
21+
export class ConfigWatcher implements vscode.Disposable {
22+
private watcher?: vscode.FileSystemWatcher;
23+
private emitter = new vscode.EventEmitter<IConfigUpdate>();
24+
private configFiles: IConfigSource[] = [];
25+
26+
constructor(private pattern: string) {
27+
28+
}
29+
30+
31+
get onConfigUpdate(): vscode.Event<IConfigUpdate> {
32+
return this.emitter.event;
33+
}
34+
35+
async watch() {
36+
const files = await vscode.workspace.findFiles(this.pattern);
37+
const configFiles: IConfigSource[] = [];
38+
for (let i = 0; i < files.length; i++) {
39+
const fileUri = files[i];
40+
const ws = path.dirname(fileUri.toString());
41+
if (ws) {
42+
configFiles.push({
43+
workspace: ws,
44+
uri: fileUri.toString(),
45+
path: fileUri.fsPath
46+
});
47+
}
48+
}
49+
50+
this.watcher = vscode.workspace.createFileSystemWatcher(this.pattern);
51+
this.watcher.onDidCreate(uri => this.updateConfig(UpdateType.Created, uri));
52+
this.watcher.onDidChange(uri => this.updateConfig(UpdateType.Changed, uri));
53+
this.watcher.onDidDelete(uri => this.updateConfig(UpdateType.Deleted, uri));
54+
55+
this.configFiles = configFiles;
56+
return configFiles;
57+
}
58+
59+
private findConfig(uri: vscode.Uri): IConfigSource | undefined {
60+
return this.configFiles.find(it => it.uri === uri.toString());
61+
}
62+
63+
private async updateConfig(type: UpdateType, uri: vscode.Uri) {
64+
let config = this.findConfig(uri);
65+
if (config) {
66+
if (type === UpdateType.Deleted) {
67+
const index = this.configFiles.indexOf(config);
68+
this.configFiles.splice(index, 1);
69+
}
70+
}
71+
else {
72+
const ws = await vscode.workspace.getWorkspaceFolder(uri);
73+
if (!ws) {
74+
return;
75+
}
76+
config = {
77+
workspace: ws.uri.toString(),
78+
uri: uri.toString(),
79+
path: uri.fsPath
80+
};
81+
this.configFiles.push(config);
82+
type = UpdateType.Created;
83+
}
84+
this.emitter.fire({ type: type, source: config });
85+
}
86+
87+
dispose() {
88+
if (this.watcher) {
89+
this.watcher.dispose();
90+
this.watcher = undefined;
91+
}
92+
}
93+
}

client/src/languageserver.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ import {
2020
ServerOptions,
2121
DocumentSelector,
2222
} from 'vscode-languageclient/node';
23+
import { ConfigWatcher, IConfigUpdate } from "./ConfigWatcher";
24+
2325

2426
let defaultClient: LuaClient;
27+
let editorConfigWatcher: ConfigWatcher;
2528
let clients: Map<string, LuaClient> = new Map();
2629

2730
type HintResult = {
@@ -57,6 +60,17 @@ function registerCustomCommands(context: ExtensionContext) {
5760
}))
5861
}
5962

63+
function registerConfigWatch(context: ExtensionContext) {
64+
editorConfigWatcher = new ConfigWatcher('**/.editorconfig');
65+
66+
editorConfigWatcher.onConfigUpdate(onEditorConfigUpdate);
67+
context.subscriptions.push(editorConfigWatcher);
68+
}
69+
70+
function onEditorConfigUpdate(e: IConfigUpdate) {
71+
defaultClient?.client?.sendRequest('config/editorconfig/update', e);
72+
}
73+
6074
let _sortedWorkspaceFolders: string[] | undefined;
6175
function sortedWorkspaceFolders(): string[] {
6276
if (_sortedWorkspaceFolders === void 0) {
@@ -91,15 +105,14 @@ function getOuterMostWorkspaceFolder(folder: WorkspaceFolder): WorkspaceFolder {
91105
}
92106

93107
class LuaClient {
94-
private context: ExtensionContext;
95-
private documentSelector: DocumentSelector;
96-
protected client: LanguageClient;
97-
constructor(context: ExtensionContext, documentSelector: DocumentSelector) {
98-
this.context = context;
99-
this.documentSelector = documentSelector;
108+
109+
public client: LanguageClient;
110+
constructor(private context: ExtensionContext,
111+
private documentSelector: DocumentSelector) {
100112
}
101113

102-
async start() {
114+
async start() {
115+
const editorConfigFiles = await editorConfigWatcher.watch();
103116
// Options to control the language client
104117
let clientOptions: LanguageClientOptions = {
105118
// Register the server for plain text documents
@@ -110,6 +123,7 @@ class LuaClient {
110123
},
111124
initializationOptions: {
112125
changeConfiguration: true,
126+
editorConfigFiles
113127
}
114128
};
115129

@@ -336,6 +350,7 @@ function onInlayHint(client: LanguageClient) {
336350

337351
export function activate(context: ExtensionContext) {
338352
registerCustomCommands(context);
353+
registerConfigWatch(context);
339354
function didOpenTextDocument(document: TextDocument) {
340355
// We are only interested in language mode text
341356
if (document.languageId !== 'lua' || (document.uri.scheme !== 'file' && document.uri.scheme !== 'untitled')) {

0 commit comments

Comments
 (0)