Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the Edit global config command #559

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
/odinfmt
tests/tests
ols.json
.vscode/
.vscode/
deno.lock
5 changes: 5 additions & 0 deletions editors/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
50 changes: 31 additions & 19 deletions editors/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion editors/vscode/src/toolchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Loading