Skip to content

Commit

Permalink
Update handle nimsuggest chk command
Browse files Browse the repository at this point in the history
  • Loading branch information
kosz78 committed Mar 9, 2017
1 parent 8c88f70 commit 124c884
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
17 changes: 14 additions & 3 deletions src/nimBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import path = require('path');
import os = require('os');
import fs = require('fs');
import { getNimExecPath, getProjectFile, getProjects, isProjectMode } from './nimUtils';
import { execNimSuggest, NimSuggestType } from './nimSuggestExec';
import { execNimSuggest, NimSuggestType, NimSuggestResult } from './nimSuggestExec';

export interface ICheckResult {
file: string;
Expand Down Expand Up @@ -119,6 +119,18 @@ function parseErrors(lines: string[]): ICheckResult[] {
return ret;
}

function parseNimsuggestErrors(items: NimSuggestResult[]): ICheckResult[] {
var ret: ICheckResult[] = [];
for (var i = 0; i < items.length; i++) {
let item = items[i];
if (item.path === '???' && item.type === 'Hint') {
continue;
}
ret.push({ file: item.path, line: item.line, column: item.column, msg: item.documentation, severity: item.type });
}
return ret;
}

export function check(filename: string, nimConfig: vscode.WorkspaceConfiguration): Promise<ICheckResult[]> {
var runningToolsPromises = [];
var cwd = path.dirname(filename);
Expand All @@ -128,8 +140,7 @@ export function check(filename: string, nimConfig: vscode.WorkspaceConfiguration
runningToolsPromises.push(new Promise((resolve, reject) => {
execNimSuggest(NimSuggestType.chk, filename, 0, 0, '').then(items => {
if (items.length > 0) {
let parts = items[0].suggest.replace(/\\,/g, '').replace(/u000D/g, '').replace(/\\/g, '\\').split('u000A');
resolve(parseErrors(parts));
resolve(parseNimsuggestErrors(items));
} else {
resolve([]);
}
Expand Down
9 changes: 5 additions & 4 deletions src/nimMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ function runCheck(document: vscode.TextDocument) {
if (error.msg.indexOf('\'') >= 0) {
endColumn += error.msg.lastIndexOf('\'') - error.msg.indexOf('\'') - 2;
}
let range = new vscode.Range(error.line - 1, error.column - 1, error.line - 1, endColumn);
let line = Math.max(0, error.line - 1)
let range = new vscode.Range(line, Math.max(0, error.column - 1), line, endColumn);
let diagnostic = new vscode.Diagnostic(range, error.msg, mapSeverityToVSCodeSeverity(error.severity));
let diagnostics = diagnosticMap.get(targetUri);
if (!diagnostics) {
Expand Down Expand Up @@ -188,18 +189,18 @@ function runFile() {
terminal.show(true);
if (editor.document.isUntitled) {
terminal.sendText('nim ' + vscode.workspace.getConfiguration('nim')['buildCommand'] +
' -r "' + getDirtyFile(editor.document)+'"', true);
' -r "' + getDirtyFile(editor.document) + '"', true);
} else {
if (editor.document.isDirty) {
editor.document.save().then((success: boolean) => {
if (success) {
terminal.sendText('nim ' + vscode.workspace.getConfiguration('nim')['buildCommand'] +
' -r "' + editor.document.fileName+'"', true);
' -r "' + editor.document.fileName + '"', true);
}
});
} else {
terminal.sendText('nim ' + vscode.workspace.getConfiguration('nim')['buildCommand'] +
' -r "' + editor.document.fileName+'"', true);
' -r "' + editor.document.fileName + '"', true);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/nimSuggestExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,15 @@ export async function closeNimSuggestProcess(filename: string): Promise<void> {
async function getNimSuggestProcess(nimProject: string): Promise<NimSuggestProcessDescription> {
if (!nimSuggestProcessCache[nimProject]) {
nimSuggestProcessCache[nimProject] = new Promise<NimSuggestProcessDescription>((resolve, reject) => {
let nimConfig = vscode.workspace.getConfiguration('nim')
var args = ['--epc', '--v2'];
if (!!vscode.workspace.getConfiguration('nim').get('logNimsuggest')) {
if (!!nimConfig['logNimsuggest']) {
args.push('--log');
}
if (!!nimConfig['useNimsuggestCheck']) {
args.push('--refresh:on');
}

args.push(nimProject);
let process = cp.spawn(getNimSuggestPath(), args, { cwd: vscode.workspace.rootPath });
process.stdout.once('data', (data) => {
Expand Down

0 comments on commit 124c884

Please sign in to comment.