aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2025-01-11 19:52:31 +0100
committerDanielGavin <danielgavin5@hotmail.com>2025-01-11 19:52:31 +0100
commitd22499ba966d2c2c8bb0cd4aee8ced52b986ed74 (patch)
treef58615f9bbcf3392292b25c06ffdd3227c6e0dfd /editors
parent88a91d1328c9b48b45f97e3dc8a03f7767ef8162 (diff)
parenteec5781241a4127488e1606fdfb6672cd193a948 (diff)
Merge branch 'master' of https://github.com/DanielGavin/ols
Diffstat (limited to 'editors')
-rw-r--r--editors/vscode/package.json12
-rw-r--r--editors/vscode/src/extension.ts107
-rw-r--r--editors/vscode/src/toolchain.ts2
3 files changed, 78 insertions, 43 deletions
diff --git a/editors/vscode/package.json b/editors/vscode/package.json
index 82bdbc7..f431984 100644
--- a/editors/vscode/package.json
+++ b/editors/vscode/package.json
@@ -14,9 +14,6 @@
"categories": [
"Programming Languages"
],
- "activationEvents": [
- "onLanguage:odin"
- ],
"icon": "images/emblem.png",
"main": "./out/extension.js",
"contributes": {
@@ -37,8 +34,13 @@
"category": "Odin Language Server"
},
{
- "command": "ols.createOls",
- "title": "Create ols.json file in project",
+ "command": "ols.editProjectConfig",
+ "title": "Edit per-project config file (ols.json), creating it if necessary",
+ "category": "Odin Language Server"
+ },
+ {
+ "command": "ols.editUserConfig",
+ "title": "Edit per-user config file (ols.json), creating it if necessary",
"category": "Odin Language Server"
}
],
diff --git a/editors/vscode/src/extension.ts b/editors/vscode/src/extension.ts
index e3a8f4f..ae776f8 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,24 @@ 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 = JSON.stringify(
+ {
+ $schema: "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/ols.schema.json",
+ enable_document_symbols: true,
+ enable_hover: true,
+ enable_snippets: true
+ },
+ null,
+ 4,
+);
+
let ctx: Ctx;
export async function activate(context: vscode.ExtensionContext) {
@@ -102,32 +113,40 @@ export async function activate(context: vscode.ExtensionContext) {
ctx.registerCommand("runDebugTest", runDebugTest);
ctx.registerCommand("runTest", runTest);
- const olsFile = path.join(workspaceFolder.uri.fsPath, "ols.json");
-
- fs.access(olsFile, constants.F_OK).catch(async err => {
- if (err) {
+ const projectConfigPath = path.join(workspaceFolder.uri.fsPath, "ols.json");
+ const userConfigPath = path.join(path.dirname(serverPath), "ols.json");
+ fs.access(projectConfigPath, constants.F_OK).catch(async (_e1) => {
+ fs.access(userConfigPath, constants.F_OK).catch( async (_e2) => {
if (!config.askCreateOLS) {
return;
}
const userResponse = await vscode.window.showInformationMessage(
- "No ols config file in the workspace root folder. Do you wish to create one?",
+ "No ols config file found. Do you wish to create one?",
"Yes",
"No",
- "Don't ask again"
+ "Don't ask again",
);
if (userResponse === "Yes") {
- createOlsConfig(ctx);
+ const clarification = await vscode.window.showInformationMessage(
+ "should it be specific to this project or to all your odin projects?",
+ "This project",
+ "All projects",
+ );
+ if (clarification == "This project") {
+ createOrEditProjectConfig();
+ parseOlsFile(config, projectConfigPath);
+ } else {
+ createOrEditUserConfig(serverPath);
+ parseOlsFile(config, userConfigPath);
+ }
} else if (userResponse === "Don't ask again") {
config.updateAskCreateOLS(false);
return;
}
-
- }
-
- parseOlsFile(config, olsFile);
+ })
});
if(!isOdinInstalled()) {
@@ -147,14 +166,18 @@ export async function activate(context: vscode.ExtensionContext) {
client.start();
});
- vscode.commands.registerCommand("ols.createOls", async() => {
- createOlsConfig(ctx);
+ vscode.commands.registerCommand("ols.editProjectConfig", async() => {
+ createOrEditProjectConfig();
+ });
+
+ vscode.commands.registerCommand("ols.editUserConfig", async () => {
+ createOrEditUserConfig(serverPath);
});
client.start();
- parseOlsFile(config, olsFile);
- watchOlsConfigFile(ctx, olsFile);
+ parseOlsFile(config, projectConfigPath);
+ watchOlsConfigFile(ctx, projectConfigPath);
}
async function bootstrap(config: Config, state: PersistentState): Promise<string> {
@@ -219,35 +242,45 @@ 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
- };
-
- const olsPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
+export function createOrEditProjectConfig() {
+ const projectConfigPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
+ openFileAndCreateIfNotExists("ols.json", projectConfigPath, defaultConfig);
+}
- const edit = new vscode.WorkspaceEdit();
+export function createOrEditUserConfig(serverPath: string) {
+ const userConfigPath = path.dirname(serverPath);
+ openFileAndCreateIfNotExists("ols.json", userConfigPath, defaultConfig);
+}
- const content = JSON.stringify(config, null, 4);
+function openFileAndCreateIfNotExists(file: string, folder: string, defaultContents: string) {
+ const filePath = path.join(folder, file);
+ console.log(filePath);
- writeFileSync(path.join(olsPath, "ols.json"), content);
+ vscode.workspace.openTextDocument(filePath).then(
+ (document) => { vscode.window.showTextDocument(document) },
+ () => {
+ writeFileSync(filePath, defaultContents);
+ vscode.workspace.openTextDocument(filePath).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)
*/
- fs.readFile(file).then((data) => {
- const conf = JSON.parse(data.toString());
- config.collections = conf.collections;
- });
+ fs.readFile(file).then(
+ (data) => {
+ const conf = JSON.parse(data.toString());
+ config.collections = conf.collections;
+ },
+ (error) => {
+ console.info("no ols.json found in workspace");
+ },
+ );
}
function serverPath(config: Config): string | null {
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)
}
}