-
-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathvscode_utils.ts
More file actions
50 lines (39 loc) · 1.74 KB
/
Copy pathvscode_utils.ts
File metadata and controls
50 lines (39 loc) · 1.74 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
import * as vscode from "vscode";
import { globals } from "../extension";
const EXTENSION_PREFIX = "godotTools";
export function get_configuration(name: string, defaultValue?: any) {
const configValue = vscode.workspace.getConfiguration(EXTENSION_PREFIX).get(name, null);
if (defaultValue && configValue === null) {
return defaultValue;
}
return configValue;
}
export function set_configuration(name: string, value: any) {
return vscode.workspace.getConfiguration(EXTENSION_PREFIX).update(name, value);
}
const CONTEXT_PREFIX = `${EXTENSION_PREFIX}.context.`;
export function set_context(name: string, value: any) {
return vscode.commands.executeCommand("setContext", CONTEXT_PREFIX + name, value);
}
export function register_command(command: string, callback: (...args: any[]) => any, thisArg?: any): vscode.Disposable {
return vscode.commands.registerCommand(`${EXTENSION_PREFIX}.${command}`, callback);
}
export function get_extension_uri(...paths: string[]) {
return vscode.Uri.joinPath(vscode.extensions.getExtension("geequlim.godot-tools").extensionUri, ...paths ?? "");
}
/**
* Returns either a tab or spaces depending on the user config
*/
export function tabString(document?: vscode.TextDocument): string {
const editor = vscode.window.activeTextEditor;
const doc = document ?? editor?.document;
if (!doc) {
const editorConfig = vscode.workspace.getConfiguration("editor");
const insertSpaces = editorConfig.get<boolean>("insertSpaces", true);
const tabSize = editorConfig.get<number>("tabSize", 4);
return insertSpaces ? " ".repeat(tabSize) : "\t";
}
const { insertSpaces, tabSize } = vscode.window.activeTextEditor?.options ?? {};
const size = typeof tabSize === "number" ? tabSize : 4;
return insertSpaces ? " ".repeat(size) : "\t";
}