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

Download language server on startup #68

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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 esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ async function main() {
'README.md': './README.md',
'language-configuration.json': './language-configuration.json',
'package.json': './package.json',
'language-server/build/libs/language-server-all.jar': 'bin',
'node_modules/mermaid/dist/mermaid.min.js': 'media',
};
if( !production )
files['language-server/build/libs/language-server-all.jar'] = 'bin'
await build({
entryPoints: [
'src/extension.ts'
Expand Down
8 changes: 8 additions & 0 deletions package-lock.json

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

11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@
"type": "boolean",
"default": false,
"description": "Enable additional warnings for things like future deprecations, discouraged patterns, and so on."
},
"nextflow.targetVersion": {
"type": "string",
"default": null,
"markdownDescription": "Target version of Nextflow to be used by the language server."
}
}
}
Expand All @@ -154,6 +159,7 @@
"package": "npm run check-types && node esbuild.js --production && (cd build ; vsce package -o nextflow.vsix)"
},
"devDependencies": {
"@microsoft/vscode-file-downloader-api": "^1.0.1",
"@types/node": "^20",
"@types/vscode": "^1.73.1",
"@vscode/vsce": "^3.2.1",
Expand All @@ -163,5 +169,8 @@
"typescript": "^5.7.2",
"vscode-jsonrpc": "^8.0.2",
"vscode-languageclient": "^8.0.2"
}
},
"extensionDependencies": [
"mindaro-dev.file-downloader"
]
}
43 changes: 38 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import buildMermaid from "./utils/buildMermaid";
import findJava from "./utils/findJava";
import * as fs from 'fs';
import * as path from "path";
import * as vscode from "vscode";
import { getApi } from "@microsoft/vscode-file-downloader-api";
import {
LanguageClient,
LanguageClientOptions,
Expand All @@ -13,6 +15,35 @@ let extensionContext: vscode.ExtensionContext | null = null;
let languageClient: LanguageClient | null = null;
let javaPath: string | null = null;

function getDefaultVersion() {
return "1.0.3";
}

async function getLanguageServerPath() {
if (!extensionContext) {
return null;
}
const devPath = path.resolve(
extensionContext.extensionPath,
"bin",
"language-server-all.jar"
);
if( fs.existsSync(devPath) ) {
vscode.window.showInformationMessage("Using local build of language server.");
return devPath;
}
const version = vscode.workspace
.getConfiguration("nextflow")
.get("targetVersion") as string ?? getDefaultVersion();
const fileDownloader = await getApi();
const serverUri = await fileDownloader.downloadFile(
vscode.Uri.parse(`https://github.com/nextflow-io/language-server/releases/download/v${version}/language-server-all.jar`),
"language-server-all.jar",
extensionContext
);
return serverUri.fsPath;
}

function startLanguageServer() {
vscode.window.withProgress(
{ location: vscode.ProgressLocation.Window },
Expand Down Expand Up @@ -57,13 +88,15 @@ function startLanguageServer() {
protocol2Code: (value) => vscode.Uri.parse(value),
},
};
let serverPath = await getLanguageServerPath();
if (!serverPath) {
resolve();
vscode.window.showErrorMessage("Failed to retrieve language server.");
return;
}
let args = [
"-jar",
path.resolve(
extensionContext.extensionPath,
"bin",
"language-server-all.jar"
),
serverPath,
];
// uncomment to allow a debugger to attach to the language server
// args.unshift("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005,quiet=y");
Expand Down