Skip to content
Open
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]: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...".
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
87 changes: 78 additions & 9 deletions src/activateViashSchema.ts
Original file line number Diff line number Diff line change
@@ -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;
}

Expand All @@ -14,18 +66,35 @@ export async function activateViashSchema(context: vscode.ExtensionContext) {
const config = vscode.workspace.getConfiguration("yaml");
const schemas = config.get<any>("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}'.`
);
}
12 changes: 0 additions & 12 deletions src/getViashSchemaFile.ts

This file was deleted.

6 changes: 4 additions & 2 deletions src/getViashVersion.ts → src/viash/version.ts
Original file line number Diff line number Diff line change
@@ -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 <version> (c) <year> <author>'
return stdout.toString().trim().split(" ")[1];
Expand Down
1 change: 1 addition & 0 deletions src/viashTestAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ViashTestAdapter {
if (this.isViashConfigFile(document.uri)) {
this.load();
}
// todo: handle package files
})
);

Expand Down