-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvscode.ts
More file actions
153 lines (136 loc) · 4.34 KB
/
vscode.ts
File metadata and controls
153 lines (136 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
* Mock for the `vscode` module.
*
* Used via resolve.alias in vitest.config.ts so that all imports of
* 'vscode' resolve to this file during tests.
*
* Does NOT use vi.fn() — uses plain functions/objects so it can be
* loaded as a regular module without vitest bootstrapping.
*/
const noop = () => {};
const noopReturn = (val: any) => () => val;
function createEventEmitter() {
const listeners: Function[] = [];
return {
event: (listener: Function) => {
listeners.push(listener);
return { dispose: noop };
},
fire: (...args: unknown[]) => {
for (const l of listeners) l(...args);
},
dispose: () => { listeners.length = 0; },
};
}
function createOutputChannelMock() {
return {
appendLine: noop, append: noop, clear: noop, show: noop,
hide: noop, dispose: noop, info: noop, warn: noop,
error: noop, debug: noop, trace: noop, logLevel: 3,
name: 'CodeQL MCP', onDidChangeLogLevel: noop,
replace: noop,
};
}
function createFileSystemWatcherMock() {
return {
onDidCreate: noopReturn({ dispose: noop }),
onDidChange: noopReturn({ dispose: noop }),
onDidDelete: noopReturn({ dispose: noop }),
ignoreCreateEvents: false,
ignoreChangeEvents: false,
ignoreDeleteEvents: false,
dispose: noop,
};
}
function createConfigMock() {
return {
get: (_key: string, defaultVal?: any) => defaultVal,
has: () => false,
inspect: () => undefined,
update: () => Promise.resolve(),
};
}
export class EventEmitter {
private _emitter = createEventEmitter();
get event() { return this._emitter.event; }
fire(...args: unknown[]) { this._emitter.fire(...args); }
dispose() { this._emitter.dispose(); }
}
export const Uri = {
file: (p: string) => ({ fsPath: p, scheme: 'file', path: p }),
joinPath: (b: any, ...s: string[]) => ({
fsPath: [b.fsPath, ...s].join('/'),
scheme: 'file',
path: [b.path, ...s].join('/'),
}),
parse: (v: string) => ({ fsPath: v, scheme: 'file', path: v }),
};
export const workspace = {
getConfiguration: () => createConfigMock(),
createFileSystemWatcher: () => createFileSystemWatcherMock(),
workspaceFolders: [] as any[],
onDidChangeConfiguration: noopReturn({ dispose: noop }),
onDidChangeWorkspaceFolders: noopReturn({ dispose: noop }),
onDidCreateFiles: noopReturn({ dispose: noop }),
onDidSaveTextDocument: noopReturn({ dispose: noop }),
fs: { stat: noop, readFile: noop, readDirectory: noop },
asRelativePath: (pathOrUri: any) => {
const p = typeof pathOrUri === 'string' ? pathOrUri : pathOrUri?.fsPath ?? String(pathOrUri);
return p;
},
updateWorkspaceFolders: () => true,
};
export const window = {
createOutputChannel: () => createOutputChannelMock(),
showInformationMessage: noop,
showWarningMessage: noop,
showErrorMessage: noop,
createStatusBarItem: () => ({
show: noop, hide: noop, dispose: noop,
text: '', tooltip: '', command: undefined,
}),
onDidChangeActiveTextEditor: noopReturn({ dispose: noop }),
};
export const commands = {
registerCommand: () => ({ dispose: noop }),
executeCommand: noop,
};
export const extensions = {
getExtension: () => undefined,
all: [],
onDidChange: noopReturn({ dispose: noop }),
};
export const tasks = {
onDidEndTask: noopReturn({ dispose: noop }),
onDidEndTaskProcess: noopReturn({ dispose: noop }),
};
export const languages = {
onDidChangeDiagnostics: noopReturn({ dispose: noop }),
};
export const lm = {
registerMcpServerDefinitionProvider: () => ({ dispose: noop }),
};
export class Disposable {
private _callOnDispose: () => void;
constructor(callOnDispose: () => void) { this._callOnDispose = callOnDispose; }
static from(...disposableLikes: Array<{ dispose: () => any }>) {
return new Disposable(() => { for (const d of disposableLikes) d.dispose(); });
}
dispose() { this._callOnDispose(); }
}
export const StatusBarAlignment = { Left: 1, Right: 2 };
export const ConfigurationTarget = { Global: 1, Workspace: 2, WorkspaceFolder: 3 };
export class McpStdioServerDefinition {
label: string;
command: string;
args: string[];
env: Record<string, string>;
version?: string;
constructor(label: string, command: string, args?: string[], env?: Record<string, string>, version?: string) {
this.label = label;
this.command = command;
this.args = args ?? [];
this.env = env ?? {};
this.version = version;
}
}