diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000..5f23cc6a --- /dev/null +++ b/.npmignore @@ -0,0 +1,3 @@ +.DS_Store +npm-debug.log +/node_modules diff --git a/lib/linter-integration.js b/lib/linter-integration.js index 924dd14b..7d8e4205 100644 --- a/lib/linter-integration.js +++ b/lib/linter-integration.js @@ -1,14 +1,32 @@ 'use babel'; +import { CompositeDisposable } from 'atom'; + class Linter { constructor(registry) { - this.linter = registry.register({ name: 'Build' }); + const _this = this; + this.linter = registry({ name: 'Build' }); + this.subscriptions = new CompositeDisposable(); + + // Setting and clearing messages per filePath + this.subscriptions.add(atom.workspace.observeTextEditors(function (textEditor) { + _this.editorPath = textEditor.getPath(); + if (!_this.editorPath) { + return; + } + const subscription = textEditor.onDidDestroy(function () { + _this.subscriptions.remove(subscription); + _this.linter.setMessages(_this.editorPath, []); + }); + _this.subscriptions.add(subscription); + })); } destroy() { - this.linter.dispose(); + // this.linter.dispose(); + this.subscriptions.dispose(); } clear() { - this.linter.deleteMessages(); + this.linter.clearMessages(); } processMessages(messages, cwd) { function extractRange(json) { @@ -29,22 +47,19 @@ class Linter { default: return null; } } - this.linter.setMessages(messages.map(match => ({ - type: match.type || 'Error', - text: !match.message && !match.html_message ? 'Error from build' : match.message, - html: match.message ? undefined : match.html_message, - filePath: normalizePath(match.file), - severity: typeToSeverity(match.type), - range: extractRange(match), - trace: match.trace && match.trace.map(trace => ({ - type: trace.type || 'Trace', - text: !trace.message && !trace.html_message ? 'Trace in build' : trace.message, - html: trace.message ? undefined : trace.html_message, - filePath: trace.file && normalizePath(trace.file), - severity: typeToSeverity(trace.type) || 'info', - range: extractRange(trace) - })) - }))); + this.linter.setMessages(this.editorPath, (messages.map(match => ({ + severity: typeToSeverity(match.type) || 'info', + location: { + file: normalizePath(match.file), + position: extractRange(match) + }, + excerpt: !match.message && !match.html_message + ? 'Error from build' + : match.message, + description: match.message + ? undefined + : match.html_message + })))); } } diff --git a/package.json b/package.json index 8a6b52be..7855e25a 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "linter-indie": { "versions": { - "1.0.0": "consumeLinterRegistry" + "2.0.0": "consumeLinterRegistry" } } },