aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorCarlyle <hack366@pm.me>2024-12-31 13:44:56 -0800
committerCarlyle <hack366@pm.me>2024-12-31 13:44:56 -0800
commit191ef02ab1e99ce37e011c35629be02f649be4b4 (patch)
treec90239a5f1afd27ba357b159d25851354c95a8e0 /editors
parent584f01b28ae25875fb25930cc66b2ba39a77811a (diff)
added the Edit global config command
Diffstat (limited to 'editors')
-rw-r--r--editors/vscode/package.json5
-rw-r--r--editors/vscode/src/extension.ts50
-rw-r--r--editors/vscode/src/toolchain.ts2
3 files changed, 37 insertions, 20 deletions
diff --git a/editors/vscode/package.json b/editors/vscode/package.json
index 82bdbc7..6ecfd98 100644
--- a/editors/vscode/package.json
+++ b/editors/vscode/package.json
@@ -37,6 +37,11 @@
"category": "Odin Language Server"
},
{
+ "command": "ols.editGlobalOls",
+ "title": "Edit global ols.json file",
+ "category": "Odin Language Server"
+ },
+ {
"command": "ols.createOls",
"title": "Create ols.json file in project",
"category": "Odin Language Server"
diff --git a/editors/vscode/src/extension.ts b/editors/vscode/src/extension.ts
index e3a8f4f..3a6d7b9 100644
--- a/editors/vscode/src/extension.ts
+++ b/editors/vscode/src/extension.ts
@@ -5,7 +5,7 @@
import * as vscode from 'vscode';
import * as path from "path";
import * as os from "os";
-import { promises as fs, PathLike, constants, writeFileSync } from "fs";
+import { promises as fs, constants, writeFileSync} from "fs";
var AdmZip = require('adm-zip');
@@ -20,13 +20,20 @@ import { RunnableCodeLensProvider } from "./run";
import { PersistentState } from './persistent_state';
import { Config } from './config';
import { fetchRelease, download } from './net';
-import { getPathForExecutable, isOdinInstalled } from './toolchain';
+import { isOdinInstalled } from './toolchain';
import { Ctx } from './ctx';
import { runDebugTest, runTest } from './commands';
import { watchOlsConfigFile } from './watch';
const onDidChange: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
+const defaultConfig = {
+ $schema: "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/ols.schema.json",
+ enable_document_symbols: true,
+ enable_hover: true,
+ enable_snippets: true
+};
+
let ctx: Ctx;
export async function activate(context: vscode.ExtensionContext) {
@@ -151,6 +158,10 @@ export async function activate(context: vscode.ExtensionContext) {
createOlsConfig(ctx);
});
+ vscode.commands.registerCommand("ols.editGlobalOls", async () => {
+ editGlobalOlsConfig(serverPath);
+ });
+
client.start();
parseOlsFile(config, olsFile);
@@ -219,27 +230,28 @@ async function removeOldServers(config: Config, state: PersistentState): Promise
}
}
-export function createOlsConfig(ctx: Ctx) {
- const odinPath = getPathForExecutable("odin");
-
- const corePath = path.resolve(path.join(path.dirname(odinPath), "core"));
-
- const config = {
- $schema: "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/ols.schema.json",
- enable_document_symbols: true,
- enable_hover: true,
- enable_snippets: true
- };
-
+export function createOlsConfig(_ctx: Ctx) {
const olsPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
-
- const edit = new vscode.WorkspaceEdit();
-
- const content = JSON.stringify(config, null, 4);
-
+ const content = JSON.stringify(defaultConfig, null, 4);
writeFileSync(path.join(olsPath, "ols.json"), content);
}
+export async function editGlobalOlsConfig(serverPath: string) {
+ const configPath = path.join(path.dirname(serverPath), "ols.json");
+
+ vscode.workspace.openTextDocument(configPath).then(
+ (document) => { vscode.window.showTextDocument(document) },
+ () => {
+ const content = JSON.stringify(defaultConfig, null, 4);
+ writeFileSync(configPath, content);
+ vscode.workspace.openTextDocument(configPath).then(
+ (document) => { vscode.window.showTextDocument(document) }
+ );
+ }
+ );
+
+}
+
export async function parseOlsFile(config: Config, file: string) {
/*
We have to parse the collections that they have specificed through the json(This will be changed when odin gets it's own builder files)
diff --git a/editors/vscode/src/toolchain.ts b/editors/vscode/src/toolchain.ts
index 21957ed..3a559de 100644
--- a/editors/vscode/src/toolchain.ts
+++ b/editors/vscode/src/toolchain.ts
@@ -45,7 +45,7 @@ function lookupInPath(exec: string): string | undefined {
return pathToOdin;
}
} catch (realpathError) {
- console.error("realpathError:", realpathError)
+ console.debug("couldn't find odin at", candidates[i], "on account of", realpathError)
}
}