diff --git a/.gitignore b/.gitignore index 94b197c..1c6bedb 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ /odinfmt tests/tests ols.json -.vscode/ \ No newline at end of file +.vscode/ +deno.lock 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 @@ -36,6 +36,11 @@ "title": "Restart Odin Language Server", "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", 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) } }