Skip to content

Commit

Permalink
feat: prefer nightly and version override
Browse files Browse the repository at this point in the history
  • Loading branch information
Desdaemon committed Aug 31, 2023
1 parent 1f911f0 commit 3e8c5c6
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 30 deletions.
24 changes: 16 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@
"RUST_BACKTRACE": "1"
}
},
// {
// "type": "node",
// "request": "attach",
// "name": "Attach to Server",
// "port": 6009,
// "restart": true,
// "outFiles": ["${workspaceRoot}/server/out/**/*.js"]
// },
{
"type": "extensionHost",
"request": "launch",
"name": "Launch Client (Production Flow)",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "${workspaceRoot}/examples"],
"outFiles": ["${workspaceRoot}/dist/*.js"],
"preLaunchTask": {
"type": "npm",
"script": "watch"
},
"env": {
"RUST_LOG": "info",
"RUST_BACKTRACE": "1"
}
},
{
"name": "Language Server E2E Test",
"type": "extensionHost",
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "odoo-lsp"
version = "0.1.0-dev.3"
version = "0.1.1"
edition = "2021"
authors = ["Viet Dinh <[email protected]>"]
description = "Language server for Odoo Python/JS/XML"
Expand Down
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,29 @@ For more features check out the [wiki].

## Install

The VSCode extension handles downloading the latest releases automatically; other editors need `odoo-lsp` on the path.
Nightly binaries are also available for major platforms, please check [Releases] for the latest downloads.

```shell
cargo install --git https://github.com/Desdaemon/odoo-lsp
```
# One-line
wget -qO- "https://github.com/Desdaemon/odoo-lsp/releases/download/nightly-$(date +'%Y%m%d')/odoo-lsp-x86_64-unknown-linux-musl.tgz" | \
tar --transform 's/^dbt2-0.37.50.3/dbt2/' -xvz

Nightly binaries are also available for some platforms, please check [Releases] for the latest downloads.
# With cargo-binstall
cargo binstall odoo-lsp

# Install from source
cargo install odoo-lsp
```

## Setup

For usage instructions please check the [wiki] (work in progress).

### VSCode

odoo-lsp is available from the Visual Studio Marketplace and the Open VSX Registry.
Alternatively, you can grab the latest nightly builds from [Releases].
odoo-lsp is available from the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=Desdaemon.odoo-lsp) and the
[Open VSX Registry](https://open-vsx.org/extension/Desdaemon/odoo-lsp). Alternatively, you can grab the latest nightly builds from [Releases].

### Helix

Expand Down
4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"license": "MIT",
"version": "0.0.1",
"engines": {
"vscode": "^1.65.0"
"vscode": "^1.66.0"
},
"devDependencies": {
"@types/node": "^17.0.45",
"@types/vscode": "~1.65.0",
"@types/vscode": "^1.66.0",
"vscode-test": "^1.6.1"
}
}
8 changes: 4 additions & 4 deletions client/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ async function downloadLspBinary(context: ExtensionContext) {
const archiveExtension = isWindows ? ".zip" : ".tgz";
const runtimeDir = context.globalStorageUri.fsPath;
await mkdir(runtimeDir, { recursive: true });
const preferNightly = !!workspace.getConfiguration("odoo-lsp.binary").get("preferNightly");
const overrideVersion = workspace.getConfiguration("odoo-lsp.binary").get("overrideVersion");

// We follow nightly releases, so only download if today's build is not already downloaded.
// The format is nightly-YYYYMMDD
const today = new Date().toISOString().slice(0, 10).replace(/-/g, "");
const release = context.extension.packageJSON._release || `nightly-${today}`;
let release = overrideVersion || `nightly-${today}`;
if (!preferNightly && !overrideVersion) {
release = context.extension.packageJSON._release || release;
}
if (typeof release !== "string" || !release) {
window.showErrorMessage(`Bug: invalid release "${release}"`);
return;
Expand Down Expand Up @@ -114,11 +119,12 @@ async function downloadLspBinary(context: ExtensionContext) {
const shaLink = `${link}.sha256`;
const shaOutput = `${latest}.sha256`;

const powershell = { shell: "powershell.exe" };
const sh = { shell: "sh" };
if (!existsSync(latest)) {
window.setStatusBarMessage(`Downloading odoo-lsp@${release}...`, 5);
try {
if (isWindows) {
const powershell = { shell: "powershell.exe" };
await execAsync(`Invoke-WebRequest -Uri ${link} -OutFile ${latest}`, powershell);
await execAsync(`Invoke-WebRequest -Uri ${shaLink} -OutFile ${shaOutput}`, powershell);
const { stdout } = await execAsync(
Expand All @@ -128,7 +134,6 @@ async function downloadLspBinary(context: ExtensionContext) {
if (stdout.toString().trim() !== "True") throw new Error("Checksum verification failed");
await execAsync(`Expand-Archive -Path ${latest} -DestinationPath ${runtimeDir}`, powershell);
} else {
const sh = { shell: "sh" };
await execAsync(`wget -O ${latest} ${link}`, sh);
await execAsync(`wget -O ${shaOutput} ${shaLink}`, sh);
await execAsync(
Expand All @@ -141,6 +146,12 @@ async function downloadLspBinary(context: ExtensionContext) {
window.showErrorMessage(`Failed to download odoo-lsp binary: ${err}`);
await rm(latest);
}
} else if (!existsSync(odooLspBin)) {
if (isWindows) {
await execAsync(`Expand-Archive -Path ${latest} -DestinationPath ${runtimeDir}`, powershell);
} else {
await execAsync(`tar -xzf ${latest} -C ${runtimeDir}`, sh);
}
}

if (existsSync(odooLspBin)) return odooLspBin;
Expand Down Expand Up @@ -171,7 +182,7 @@ async function openLink(url: string) {
export async function activate(context: ExtensionContext) {
const traceOutputChannel = window.createOutputChannel("Odoo LSP");
let command = process.env.SERVER_PATH || "odoo-lsp";
if (!(await which(command)) && context.extensionMode === ExtensionMode.Production) {
if (!(await which(command))) {
command = (await downloadLspBinary(context)) || command;
}
traceOutputChannel.appendLine(`odoo-lsp executable: ${command}`);
Expand Down
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "odoo-lsp",
"description": "Language server for Odoo Python/JS/XML",
"license": "MIT",
"version": "0.1.0",
"version": "0.1.1",
"categories": [
"Programming Languages"
],
Expand Down Expand Up @@ -61,8 +61,17 @@
"items": {
"type": "string"
},
"description": "List of module roots similar to `--addons-path`, either absolute or relative to the workspace root. Overrides any configuration files if exists. Accepts globs.",
"markdownDescription": "List of module roots similar to `--addons-path`, either absolute or relative to the workspace root. Overrides any configuration files if exists. Accepts globs.",
"default": []
},
"odoo-lsp.binary.preferNightly": {
"type": "boolean",
"default": true,
"description": "Prefer nightly versions of odoo-lsp binaries. Set to false if you encounter any bugs with nightly binaries."
},
"odoo-lsp.binary.overrideVersion": {
"type": "string",
"description": "Always download a specific version of odoo-lsp, mainly used for debugging build issues. For example, nightly versions follow the format of 'nightly-YYYYMMDD'."
}
}
}
Expand All @@ -76,7 +85,7 @@
"test-compile": "tsc -p ./",
"compile": "cross-env NODE_ENV=production tsc -b",
"watch": "rm -rf dist && tsc -b -w",
"lint": "prettier --write . && cargo +nightly fmt",
"lint": "prettier --write . && cargo fmt",
"pretest": "npm run compile && npm run lint",
"test": "node ./out/test/runTest.js",
"build": "webpack --config webpack.config.js",
Expand All @@ -89,7 +98,7 @@
"@types/glob": "^7.2.0",
"@types/mocha": "^8.2.3",
"@types/node": "^12.20.55",
"@types/vscode": "1.66.0",
"@types/vscode": "^1.66.0",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"@vscode/test-electron": "^2.3.4",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3e8c5c6

Please sign in to comment.