-
Notifications
You must be signed in to change notification settings - Fork 287
Add completion feature #41
Changes from 6 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,46 @@ function balanceEvent(event) { | |
if (event && event.document) balancePairs(event.document); | ||
} | ||
|
||
var completeCmd; | ||
|
||
function completionProvider(document, position, token) { | ||
return new Promise((resolve, reject) => { | ||
const line = position.line + 1; | ||
const column = position.character; | ||
|
||
var child = cp.spawn(completeCmd, [ | ||
'--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) => { | ||
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 (/^[^\w]/.test(items[0])) return; | ||
var completionItem = new vscode.CompletionItem(items[0]); | ||
completionItem.detail = items[1]; | ||
completionItem.documentation = items[1]; | ||
completionItem.filterText = items[0]; | ||
completionItem.insertText = items[0]; | ||
completionItem.label = items[0]; | ||
completionItem.kind = vscode.CompletionItemKind.Method; | ||
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 +200,14 @@ function activate(context) { | |
balancePairs(vscode.window.activeTextEditor.document); | ||
} | ||
|
||
which("rct-complete", function(err, found) { | ||
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. I'm not really a fan of this call because I use Also, this may cause a problem if the user installs it for one version of ruby, but the shell that is spawned for I guess it's ok like this until the issues start coming in. If they don't, then all is well. 😉 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. Thanks for your review. I don't like handling completion event even though rct-cmplete is not installed. How about to try to run 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. Ah, I just remember why I did this imlement. 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. Sorry, I figure out this problem. I'm using msys2 mingw64 environment. And ruby on mingw64 doesn't allow non-absolute path in the command. |
||
if (!err && found) { | ||
completeCmd = found; | ||
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.
To make this read better in English, maybe try this:
Move the
- IntelliSense and autocomplete
line from TODO into Features.