-
Notifications
You must be signed in to change notification settings - Fork 287
Add completion feature #41
Changes from 2 commits
73f4c04
8e907eb
4651e1d
f9a8e72
c931e57
3f78b70
03476ab
404f212
713c75a
739f1ca
4a3803e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
"use strict"; | ||
let vscode = require('vscode'); | ||
let linters = require('./lint/lint'); | ||
let cp = require('child_process'); | ||
let which = require('which'); | ||
|
||
const severities = { | ||
refactor: vscode.DiagnosticSeverity.Hint, | ||
convention: vscode.DiagnosticSeverity.Information, | ||
|
@@ -104,6 +107,54 @@ function balanceEvent(event) { | |
if (event && event.document) balancePairs(event.document); | ||
} | ||
|
||
function completionProvider(document, position, token) { | ||
return new Promise((resolve, reject) => { | ||
const line = position.line + 1; | ||
const column = position.character; | ||
console.log("line=" , line); | ||
console.log("column=" , column); | ||
|
||
var sh, flag; | ||
if (process.platform === 'win32') { | ||
sh = 'cmd'; flag = '/c'; | ||
} else { | ||
sh = '/bin/sh'; flag = '-c'; | ||
} | ||
var child = cp.spawn(sh, [ | ||
flag, | ||
'rct-complete', | ||
'--completion-class-info', | ||
'--dev', | ||
'--fork', | ||
'--line='+line, | ||
'--column='+column], { detached: false }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
child.stderr.on('data', (data) => { | ||
console.log("stderr:", data.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop this. If it's not reported to the user interface, there's no need to report it. |
||
reject(data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this to Actually, this listener can be removed altogether. |
||
}); | ||
child.stdout.on('data', (data) => { | ||
console.log("stdout:", data.toString()); | ||
var completionItems = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Collect the completionItems in the scope, but handle the response in My preference is to collect the buffers in an array, then |
||
data.toString().split('\n').forEach(function(elem) { | ||
var items = elem.split('\t'); | ||
if (items.length != 2) return; | ||
var completionItem = new vscode.CompletionItem(items[0]); | ||
completionItem.detail = items[1]; | ||
completionItem.documentation = items[1]; | ||
completionItem.filterText = items[1]; | ||
completionItem.insertText = items[0]; | ||
completionItem.label = items[0]; | ||
completionItems.push(completionItem); | ||
}, this); | ||
if (completionItems.length == 0) | ||
return reject([]); | ||
return resolve(completionItems); | ||
}); | ||
child.stdin.write(document.getText()); | ||
child.stdin.end(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Collapse these calls into |
||
}); | ||
} | ||
|
||
function activate(context) { | ||
//add language config | ||
vscode.languages.setLanguageConfiguration('ruby', langConfig); | ||
|
@@ -157,6 +208,13 @@ function activate(context) { | |
balancePairs(vscode.window.activeTextEditor.document); | ||
} | ||
|
||
which("rct-complete", function(err) { | ||
if (err == null) { | ||
vscode.languages.registerCompletionItemProvider('ruby', { | ||
provideCompletionItems: completionProvider | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
exports.activate = activate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you may want to remove this.