added the Edit global config command
This commit is contained in:
parent
584f01b28a
commit
191ef02ab1
4 changed files with 39 additions and 21 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -15,4 +15,5 @@
|
||||||
/odinfmt
|
/odinfmt
|
||||||
tests/tests
|
tests/tests
|
||||||
ols.json
|
ols.json
|
||||||
.vscode/
|
.vscode/
|
||||||
|
deno.lock
|
||||||
|
|
|
@ -36,6 +36,11 @@
|
||||||
"title": "Restart Odin Language Server",
|
"title": "Restart Odin Language Server",
|
||||||
"category": "Odin Language Server"
|
"category": "Odin Language Server"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "ols.editGlobalOls",
|
||||||
|
"title": "Edit global ols.json file",
|
||||||
|
"category": "Odin Language Server"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "ols.createOls",
|
"command": "ols.createOls",
|
||||||
"title": "Create ols.json file in project",
|
"title": "Create ols.json file in project",
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import * as os from "os";
|
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');
|
var AdmZip = require('adm-zip');
|
||||||
|
|
||||||
|
@ -20,13 +20,20 @@ import { RunnableCodeLensProvider } from "./run";
|
||||||
import { PersistentState } from './persistent_state';
|
import { PersistentState } from './persistent_state';
|
||||||
import { Config } from './config';
|
import { Config } from './config';
|
||||||
import { fetchRelease, download } from './net';
|
import { fetchRelease, download } from './net';
|
||||||
import { getPathForExecutable, isOdinInstalled } from './toolchain';
|
import { isOdinInstalled } from './toolchain';
|
||||||
import { Ctx } from './ctx';
|
import { Ctx } from './ctx';
|
||||||
import { runDebugTest, runTest } from './commands';
|
import { runDebugTest, runTest } from './commands';
|
||||||
import { watchOlsConfigFile } from './watch';
|
import { watchOlsConfigFile } from './watch';
|
||||||
|
|
||||||
const onDidChange: vscode.EventEmitter<void> = new vscode.EventEmitter<void>();
|
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;
|
let ctx: Ctx;
|
||||||
|
|
||||||
export async function activate(context: vscode.ExtensionContext) {
|
export async function activate(context: vscode.ExtensionContext) {
|
||||||
|
@ -151,6 +158,10 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
createOlsConfig(ctx);
|
createOlsConfig(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
vscode.commands.registerCommand("ols.editGlobalOls", async () => {
|
||||||
|
editGlobalOlsConfig(serverPath);
|
||||||
|
});
|
||||||
|
|
||||||
client.start();
|
client.start();
|
||||||
|
|
||||||
parseOlsFile(config, olsFile);
|
parseOlsFile(config, olsFile);
|
||||||
|
@ -219,27 +230,28 @@ async function removeOldServers(config: Config, state: PersistentState): Promise
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createOlsConfig(ctx: Ctx) {
|
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;
|
const olsPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
|
||||||
|
const content = JSON.stringify(defaultConfig, null, 4);
|
||||||
const edit = new vscode.WorkspaceEdit();
|
|
||||||
|
|
||||||
const content = JSON.stringify(config, null, 4);
|
|
||||||
|
|
||||||
writeFileSync(path.join(olsPath, "ols.json"), content);
|
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) {
|
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)
|
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)
|
||||||
|
|
|
@ -45,7 +45,7 @@ function lookupInPath(exec: string): string | undefined {
|
||||||
return pathToOdin;
|
return pathToOdin;
|
||||||
}
|
}
|
||||||
} catch (realpathError) {
|
} catch (realpathError) {
|
||||||
console.error("realpathError:", realpathError)
|
console.debug("couldn't find odin at", candidates[i], "on account of", realpathError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue