diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ea7969..6947abf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# viash-vscode v0.3.0 + +## MAJOR CHANGES + +* Remove old schema files from vscode config (PR #6). + +* Support for multiple Workspace folders and multiple `_viash.yaml` files (PR #6). + # viash-vscode v0.2.1 ## MINOR CHANGES diff --git a/README.md b/README.md index 10a0238..cd84436 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,23 @@ Install the extension from the [Visual Studio Code Marketplace](https://marketpl ## Requirements Install Viash using [these instructions](https://viash.io/installation). + +## Development + +To contribute to the Viash VSCode extension, you need to have [Node.js](https://nodejs.org/) and [npm](https://www.npmjs.com/) installed. + +To set up the development environment, clone the repository: + +```bash +git clone git@github.com:viash-io/viash-vscode.git +cd viash-vscode +``` + +Then build the extension: + +```bash +npm install +npm run package +``` + +This will create a `.vsix` file in the `dist` directory. You can then install this file in VSCode by going to the Extensions view, clicking on the three dots in the top right corner, and selecting "Install from VSIX...". diff --git a/package-lock.json b/package-lock.json index 3a4b886..b6d3e50 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "viash", - "version": "0.2.1", + "version": "0.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "viash", - "version": "0.2.1", + "version": "0.3.0", "license": "GPL-3.0-only", "dependencies": { "vscode-test-adapter-api": "^1.9.0", diff --git a/package.json b/package.json index 7600301..392453e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "nextflow", "testing" ], - "version": "0.2.1", + "version": "0.3.0", "repository": { "type": "git", "url": "https://github.com/viash-io/viash-vscode.git" diff --git a/src/activateViashSchema.ts b/src/activateViashSchema.ts index c9a70c5..dac88ba 100644 --- a/src/activateViashSchema.ts +++ b/src/activateViashSchema.ts @@ -1,10 +1,62 @@ import * as vscode from "vscode"; -import { getViashVersion } from "./getViashVersion"; -import { getViashSchemaFile } from "./getViashSchemaFile"; +import { getViashVersion } from "./viash/version"; + +export function getViashSchemaFile( + version: string, + objectType: string = "config" +): string { + return `https://raw.githubusercontent.com/viash-io/viash-schemas/refs/heads/main/json_schemas/${version}/${objectType}.schema.json`; +} + +export function helper(projectConfigPath: string) { + if (!projectConfigPath) { + return; + } + if (!projectConfigPath.match(/\/_viash\.ya?ml$/)) { + return; + } + + const dir = projectConfigPath.replace(/\/_viash\.ya?ml$/, ""); + + const version = getViashVersion(dir); + + updateSchemas(version, dir); + + vscode.window.showInformationMessage( + `Viash schema updated for version: ${version} at ${dir}` + ); +} export async function activateViashSchema(context: vscode.ExtensionContext) { - const version = getViashVersion(); - if (!version) { + context.subscriptions.push( + vscode.workspace.onDidSaveTextDocument((document) => { + vscode.window.showInformationMessage( + `Checking if Viash schema needs to be updated for ${document.uri.fsPath}` + ); + + helper(document.uri.fsPath); + }) + ); + + // recurse current workspace folders and look for _viash.yaml files + const workspaceFolders = vscode.workspace.workspaceFolders; + if (workspaceFolders) { + for (const folder of workspaceFolders) { + const dir = folder.uri.fsPath; + const version = getViashVersion(dir); + if (version !== "unknown") { + updateSchemas(version, dir); + } + } + } +} + +function updateSchemas(version: string, folder?: string) { + vscode.window.showInformationMessage(`Updating Viash schemas for version: ${version}`); + + // Ensure viashVersion is not "unknown" here, or handle it gracefully in getViashSchemaFile + if (version === "unknown") { + vscode.window.showErrorMessage("updateSchemas called with 'unknown' Viash version. Aborting schema update."); return; } @@ -14,18 +66,35 @@ export async function activateViashSchema(context: vscode.ExtensionContext) { const config = vscode.workspace.getConfiguration("yaml"); const schemas = config.get("schemas") || {}; const origSchemas = { ...schemas }; + + // remove entries for old schemas + // TODO: need to fix this because with multiple workspaces, this will remove schemas from other workspaces + for (const schemaPath of Object.keys(schemas)) { + if (schemaPath.startsWith("https://raw.githubusercontent.com/viash-io/viash-schemas")) { + delete schemas[schemaPath]; + } + } - schemas[configSchemaPath] = ["*.vsh.yaml", "*.vsh.yml"]; - schemas[packageSchemaPath] = ["_viash.yaml", "_viash.yml"]; + if (folder) { + schemas[configSchemaPath] = [ + `${folder}/*.vsh.yaml`, + `${folder}/*.vsh.yml`, + ]; + schemas[packageSchemaPath] = [ + `${folder}/_viash.yaml`, + `${folder}/_viash.yml`, + ]; + } else { + schemas[configSchemaPath] = ["*.vsh.yaml", "*.vsh.yml"]; + schemas[packageSchemaPath] = ["_viash.yaml", "_viash.yml"]; + } - // Don't update if the schemas are the same if (JSON.stringify(schemas) === JSON.stringify(origSchemas)) { return; } - // Update the schema setting config.update("schemas", schemas, vscode.ConfigurationTarget.Workspace); vscode.window.showInformationMessage( - `Viash ${version} detected. Set schema to '${configSchemaPath}'.` + `Viash ${version} schemas updated. Config: '${configSchemaPath}', Package: '${packageSchemaPath}'.` ); } diff --git a/src/getViashSchemaFile.ts b/src/getViashSchemaFile.ts deleted file mode 100644 index e9b996c..0000000 --- a/src/getViashSchemaFile.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { getViashVersion } from "./getViashVersion"; - -export function getViashSchemaFile( - version: string | undefined = undefined, - objectType: string = "config" -): string { - if (!version) { - version = getViashVersion(); - } - - return `https://raw.githubusercontent.com/viash-io/viash-schemas/refs/heads/main/json_schemas/${version}/${objectType}.schema.json`; -} diff --git a/src/getViashVersion.ts b/src/viash/version.ts similarity index 78% rename from src/getViashVersion.ts rename to src/viash/version.ts index 566396e..bc7cc15 100644 --- a/src/getViashVersion.ts +++ b/src/viash/version.ts @@ -1,10 +1,12 @@ import * as vscode from "vscode"; import * as cp from "child_process"; -export function getViashVersion(): string { +export function getViashVersion( + folder: string +): string { try { const { stdout } = cp.spawnSync("viash", ["--version"], { - cwd: vscode.workspace.workspaceFolders?.[0].uri.fsPath, + cwd: folder, }); // stdout format: 'viash (c) ' return stdout.toString().trim().split(" ")[1]; diff --git a/src/viashTestAdapter.ts b/src/viashTestAdapter.ts index 5b20428..ac20d50 100644 --- a/src/viashTestAdapter.ts +++ b/src/viashTestAdapter.ts @@ -56,6 +56,7 @@ class ViashTestAdapter { if (this.isViashConfigFile(document.uri)) { this.load(); } + // todo: handle package files }) );