Skip to content

Commit

Permalink
Minor error handling fixes
Browse files Browse the repository at this point in the history
Add 'known' command
  • Loading branch information
kosz78 committed Mar 10, 2017
1 parent 124c884 commit aae5782
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/nimMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ function runCheck(document: vscode.TextDocument) {
if (error.msg.indexOf('\'') >= 0) {
endColumn += error.msg.lastIndexOf('\'') - error.msg.indexOf('\'') - 2;
}
let line = Math.max(0, error.line - 1)
let range = new vscode.Range(line, Math.max(0, error.column - 1), line, endColumn);
let line = Math.max(0, error.line - 1);
let range = new vscode.Range(line, Math.max(0, error.column - 1), line, Math.max(0, endColumn));
let diagnostic = new vscode.Diagnostic(range, error.msg, mapSeverityToVSCodeSeverity(error.severity));
let diagnostics = diagnosticMap.get(targetUri);
if (!diagnostics) {
Expand Down
31 changes: 21 additions & 10 deletions src/nimSuggestExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export enum NimSuggestType {
/** Returns all tokens in file (symbolType, line, pos, lenght) */
highlight,
/** Get outline symbols for file */
outline
outline,
/** Returns 'true' if given file is related to the project, otherwise 'false' */
known
}
/**
* Parsed string line from nimsuggest utility.
Expand Down Expand Up @@ -253,7 +255,7 @@ 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')
let nimConfig = vscode.workspace.getConfiguration('nim');
var args = ['--epc', '--v2'];
if (!!nimConfig['logNimsuggest']) {
args.push('--log');
Expand All @@ -265,16 +267,25 @@ async function getNimSuggestProcess(nimProject: string): Promise<NimSuggestProce
args.push(nimProject);
let process = cp.spawn(getNimSuggestPath(), args, { cwd: vscode.workspace.rootPath });
process.stdout.once('data', (data) => {
elrpc.startClient(parseInt(data.toString())).then((client) => {
client.socket.on('error', err => {
console.error(err);
let dataStr = data.toString();
let portNumber = parseInt(dataStr);
if (isNaN(portNumber)) {
reject('Nimsuggest returns unknown port number: ' + dataStr);
} else {
elrpc.startClient(portNumber).then((client) => {
client.socket.on('error', err => {
console.error(err);
});
resolve({ process: process, rpc: client });
}, (reason: any) => {
reject(reason);
});
resolve({ process: process, rpc: client });
}, (reason: any) => {
reject(reason);
});
}
});
process.on('close', () => {
process.on('close', (code: number, signal: string) => {
if (code !== 0) {
console.error('nimsuggest closed with code: ' + code + ', signal: ' + signal);
}
if (nimSuggestProcessCache[nimProject]) {
nimSuggestProcessCache[nimProject].then((desc) => {
desc.rpc.stop();
Expand Down

0 comments on commit aae5782

Please sign in to comment.