Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1021)

Unified Diff: Source/devtools/front_end/source_frame/TextEditorAutocompleteController.js

Issue 1264133002: Devtools: [WIP] Implement enhanced devtools extension language APIs Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Modify override dropdown to apply to console completions & transpile Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/source_frame/TextEditorAutocompleteController.js
diff --git a/Source/devtools/front_end/source_frame/TextEditorAutocompleteController.js b/Source/devtools/front_end/source_frame/TextEditorAutocompleteController.js
index fc755380a398e468462f08f26742386226b22807..b9961f163374f4e65439a49a7c38c99323cf8724 100644
--- a/Source/devtools/front_end/source_frame/TextEditorAutocompleteController.js
+++ b/Source/devtools/front_end/source_frame/TextEditorAutocompleteController.js
@@ -126,6 +126,53 @@ WebInspector.TextEditorAutocompleteController.prototype = {
var prefixRange = substituteRange.clone();
prefixRange.endColumn = cursor.ch;
+ var oldPrefixRange = this._prefixRange;
pfeldman 2015/08/13 21:15:47 Language support needs to be added outside of this
wes 2015/08/14 00:55:05 So if not in source_frame then in sources? (I supp
pfeldman 2015/08/17 21:15:52 Let me talk to lushnikov@ about the way we should
wes 2015/08/25 18:13:18 Any progress on this?
+ this._prefixRange = prefixRange;
+
+ var prefix = this._textEditor.copyRange(prefixRange);
+
+ if (!oldPrefixRange || prefixRange.startLine !== oldPrefixRange.startLine || prefixRange.startColumn !== oldPrefixRange.startColumn)
+ this._updateAnchorBox();
+
+ var sourceUrl = this._textEditor.url;
+ if (sourceUrl) {
+ var mime = this._textEditor.getMimeType();
+ var completionLocation = {
+ source: sourceUrl,
+ line: /** @type {number} */ (cursor.line),
+ column: /** @type {number} */ (cursor.ch)
+ };
+
+ if (WebInspector.languageService.handles.completions(mime)) {
+ var anchor = this._anchorBox; //This can be removed by other calls to _updateAnchorBox, keep it for us
+
+ /**
+ * @this {!WebInspector.TextEditorAutocompleteController}
+ */
+ function completionsReadyCallback(completions) {
+ var texts = completions.map(function(i){ return i.text; });
+ var details = completions.map(function(i){ return i.details; });
+ if (!this._suggestBox)
+ this._suggestBox = new WebInspector.SuggestBox(this, 6);
+
+ this._suggestBox.updateSuggestions(anchor, texts, 0, true, prefix, details);
+ if (!this._suggestBox.visible())
+ this.finishAutocomplete();
+ this._onSuggestionsShownForTest(texts);
+ }
+
+ var lastCompletion = this._lastCompletion = WebInspector.languageService.completions(mime, completionLocation, prefix).then((function(vals) {
+ if (lastCompletion !== this._lastCompletion) return;
+ if (!vals) {
+ completionsReadyCallback.call(this, []);
+ return;
+ }
+ completionsReadyCallback.call(this, vals);
+ }).bind(this));
+ return;
+ }
+ }
+
var wordsWithPrefix = this._delegate.wordsWithPrefix(this._textEditor, prefixRange, substituteRange);
if (!wordsWithPrefix.length) {
this.finishAutocomplete();
@@ -134,11 +181,7 @@ WebInspector.TextEditorAutocompleteController.prototype = {
if (!this._suggestBox)
this._suggestBox = new WebInspector.SuggestBox(this, 6);
- var oldPrefixRange = this._prefixRange;
- this._prefixRange = prefixRange;
- if (!oldPrefixRange || prefixRange.startLine !== oldPrefixRange.startLine || prefixRange.startColumn !== oldPrefixRange.startColumn)
- this._updateAnchorBox();
- this._suggestBox.updateSuggestions(this._anchorBox, wordsWithPrefix, 0, true, this._textEditor.copyRange(prefixRange));
+ this._suggestBox.updateSuggestions(this._anchorBox, wordsWithPrefix, 0, true, prefix);
if (!this._suggestBox.visible())
this.finishAutocomplete();
this._onSuggestionsShownForTest(wordsWithPrefix);
@@ -194,6 +237,9 @@ WebInspector.TextEditorAutocompleteController.prototype = {
*/
acceptSuggestion: function()
{
+ if (!this._prefixRange)
+ return;
+
if (this._prefixRange.endColumn - this._prefixRange.startColumn === this._currentSuggestion.length)
return;
@@ -224,7 +270,7 @@ WebInspector.TextEditorAutocompleteController.prototype = {
_onCursorActivity: function()
{
- if (!this._suggestBox)
+ if (!(this._suggestBox && this._prefixRange))
return;
var cursor = this._codeMirror.getCursor();
if (cursor.line !== this._prefixRange.startLine || cursor.ch > this._prefixRange.endColumn || cursor.ch <= this._prefixRange.startColumn)
@@ -233,6 +279,7 @@ WebInspector.TextEditorAutocompleteController.prototype = {
_updateAnchorBox: function()
{
+ if (!this._prefixRange) return;
var line = this._prefixRange.startLine;
var column = this._prefixRange.startColumn;
var metrics = this._textEditor.cursorPositionToCoordinates(line, column);

Powered by Google App Engine
This is Rietveld 408576698