diff --git a/.drone.yml b/.drone.yml index 3f2e887..734be91 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,12 +4,6 @@ pipeline: commands: - npm i - npm run lint - test: - image: node:${NODE_VERSION} - commands: - - npm i - - npm i -g vscode - - npm run test matrix: NODE_VERSION: diff --git a/package.json b/package.json index 8dbe22b..638a172 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,10 @@ "Programming Languages" ], "activationEvents": [ - "onLanguage:glsl" + "onLanguage:glsl", + "workspaceContains:**/*.fsh", + "workspaceContains:**/*.vsh", + "workspaceContains:**/*.gsh" ], "extensionDependencies": [ "slevesque.shader" diff --git a/src/extension.ts b/src/extension.ts index 8cb2216..ae898b1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,7 +2,20 @@ import * as vscode from 'vscode' import GLSLProvider from './linter/glslProvider' +import * as shell from 'shelljs' + +let glslProv: GLSLProvider; export function activate(context: vscode.ExtensionContext) { - vscode.languages.registerCodeActionsProvider('glsl', new GLSLProvider(context.subscriptions)) + glslProv = new GLSLProvider(context.subscriptions) + vscode.languages.registerCodeActionsProvider('glsl', glslProv) +} + +export function deactivate() { + try { + console.log('[MC-GLSL] disposing') + shell.rm('-rf', glslProv.getConfig().tmpdir) + } catch(e) { + console.log(e) + } } \ No newline at end of file diff --git a/src/linter/glslProvider.ts b/src/linter/glslProvider.ts index e1d894d..1e01126 100644 --- a/src/linter/glslProvider.ts +++ b/src/linter/glslProvider.ts @@ -10,9 +10,9 @@ import * as path from 'path' // glslangPath: Path to glslangValidator (assumed in PATH by default) // tmpdir: the directory into which the symlinks are stored, should be the OS's temp dir interface Config { - glslangPath: string - tmpdir: string - isWin: boolean + readonly glslangPath: string + readonly tmpdir: string + readonly isWin: boolean } // These are used for symlinking as glslangValidator only accepts files in these formats @@ -44,6 +44,8 @@ export default class GLSLProvider implements vscode.CodeActionProvider { this.diagnosticCollection = vscode.languages.createDiagnosticCollection() subs.push(this) + + // For if i ever get testing to work if (config !== null) { this.config = this.initConfig() } else { @@ -67,9 +69,11 @@ export default class GLSLProvider implements vscode.CodeActionProvider { vscode.workspace.onDidChangeConfiguration(this.configChange, this) - vscode.workspace.textDocuments.forEach((doc: vscode.TextDocument) => { - this.lint(doc) - }) + vscode.workspace.textDocuments.forEach((doc: vscode.TextDocument) => this.lint(doc)) + } + + public getConfig(): Config { + return this.config } private initConfig(): Config { @@ -130,9 +134,9 @@ export default class GLSLProvider implements vscode.CodeActionProvider { // and then remove all lines that match any of the regex private parseOutput(linkname: string): string[] { const res = cp.spawnSync(this.config.glslangPath, [linkname]).output[1].toString() - return res.split(/(?:\n)/g) - .filter((s: string) => s !== '') - .slice(1, -1) // TODO not this + return res.split('\n') + .filter((s: string) => s.length > 1) + .slice(1) .filter((s: string) => !this.matchesFilters(s)) } @@ -148,12 +152,6 @@ export default class GLSLProvider implements vscode.CodeActionProvider { const lines = this.parseOutput(linkname) - if(lines.length < 1) { - // If there were no errors, we need to set the list empty so that the editor reflects that - this.diagnosticCollection.set(document.uri, []) - return - } - const diags: vscode.Diagnostic[] = [] lines.forEach((line: string) => {