Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @implements {WebInspector.SuggestBoxDelegate} | 7 * @implements {WebInspector.SuggestBoxDelegate} |
| 8 * @param {!WebInspector.CodeMirrorTextEditor} textEditor | 8 * @param {!WebInspector.CodeMirrorTextEditor} textEditor |
| 9 * @param {!CodeMirror} codeMirror | 9 * @param {!CodeMirror} codeMirror |
| 10 */ | 10 */ |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 var cursor = this._codeMirror.getCursor("head"); | 119 var cursor = this._codeMirror.getCursor("head"); |
| 120 var substituteRange = this._delegate.substituteRange(this._textEditor, c ursor.line, cursor.ch); | 120 var substituteRange = this._delegate.substituteRange(this._textEditor, c ursor.line, cursor.ch); |
| 121 if (!substituteRange || !this._validateSelectionsContexts(substituteRang e)) { | 121 if (!substituteRange || !this._validateSelectionsContexts(substituteRang e)) { |
| 122 this.finishAutocomplete(); | 122 this.finishAutocomplete(); |
| 123 return; | 123 return; |
| 124 } | 124 } |
| 125 | 125 |
| 126 var prefixRange = substituteRange.clone(); | 126 var prefixRange = substituteRange.clone(); |
| 127 prefixRange.endColumn = cursor.ch; | 127 prefixRange.endColumn = cursor.ch; |
| 128 | 128 |
| 129 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?
| |
| 130 this._prefixRange = prefixRange; | |
| 131 | |
| 132 var prefix = this._textEditor.copyRange(prefixRange); | |
| 133 | |
| 134 if (!oldPrefixRange || prefixRange.startLine !== oldPrefixRange.startLin e || prefixRange.startColumn !== oldPrefixRange.startColumn) | |
| 135 this._updateAnchorBox(); | |
| 136 | |
| 137 var sourceUrl = this._textEditor.url; | |
| 138 if (sourceUrl) { | |
| 139 var mime = this._textEditor.getMimeType(); | |
| 140 var completionLocation = { | |
| 141 source: sourceUrl, | |
| 142 line: /** @type {number} */ (cursor.line), | |
| 143 column: /** @type {number} */ (cursor.ch) | |
| 144 }; | |
| 145 | |
| 146 if (WebInspector.languageService.handles.completions(mime)) { | |
| 147 var anchor = this._anchorBox; //This can be removed by other cal ls to _updateAnchorBox, keep it for us | |
| 148 | |
| 149 /** | |
| 150 * @this {!WebInspector.TextEditorAutocompleteController} | |
| 151 */ | |
| 152 function completionsReadyCallback(completions) { | |
| 153 var texts = completions.map(function(i){ return i.text; }); | |
| 154 var details = completions.map(function(i){ return i.details; }); | |
| 155 if (!this._suggestBox) | |
| 156 this._suggestBox = new WebInspector.SuggestBox(this, 6); | |
| 157 | |
| 158 this._suggestBox.updateSuggestions(anchor, texts, 0, true, p refix, details); | |
| 159 if (!this._suggestBox.visible()) | |
| 160 this.finishAutocomplete(); | |
| 161 this._onSuggestionsShownForTest(texts); | |
| 162 } | |
| 163 | |
| 164 var lastCompletion = this._lastCompletion = WebInspector.languag eService.completions(mime, completionLocation, prefix).then((function(vals) { | |
| 165 if (lastCompletion !== this._lastCompletion) return; | |
| 166 if (!vals) { | |
| 167 completionsReadyCallback.call(this, []); | |
| 168 return; | |
| 169 } | |
| 170 completionsReadyCallback.call(this, vals); | |
| 171 }).bind(this)); | |
| 172 return; | |
| 173 } | |
| 174 } | |
| 175 | |
| 129 var wordsWithPrefix = this._delegate.wordsWithPrefix(this._textEditor, p refixRange, substituteRange); | 176 var wordsWithPrefix = this._delegate.wordsWithPrefix(this._textEditor, p refixRange, substituteRange); |
| 130 if (!wordsWithPrefix.length) { | 177 if (!wordsWithPrefix.length) { |
| 131 this.finishAutocomplete(); | 178 this.finishAutocomplete(); |
| 132 return; | 179 return; |
| 133 } | 180 } |
| 134 | 181 |
| 135 if (!this._suggestBox) | 182 if (!this._suggestBox) |
| 136 this._suggestBox = new WebInspector.SuggestBox(this, 6); | 183 this._suggestBox = new WebInspector.SuggestBox(this, 6); |
| 137 var oldPrefixRange = this._prefixRange; | 184 this._suggestBox.updateSuggestions(this._anchorBox, wordsWithPrefix, 0, true, prefix); |
| 138 this._prefixRange = prefixRange; | |
| 139 if (!oldPrefixRange || prefixRange.startLine !== oldPrefixRange.startLin e || prefixRange.startColumn !== oldPrefixRange.startColumn) | |
| 140 this._updateAnchorBox(); | |
| 141 this._suggestBox.updateSuggestions(this._anchorBox, wordsWithPrefix, 0, true, this._textEditor.copyRange(prefixRange)); | |
| 142 if (!this._suggestBox.visible()) | 185 if (!this._suggestBox.visible()) |
| 143 this.finishAutocomplete(); | 186 this.finishAutocomplete(); |
| 144 this._onSuggestionsShownForTest(wordsWithPrefix); | 187 this._onSuggestionsShownForTest(wordsWithPrefix); |
| 145 }, | 188 }, |
| 146 | 189 |
| 147 /** | 190 /** |
| 148 * @param {!Array.<string>} suggestions | 191 * @param {!Array.<string>} suggestions |
| 149 */ | 192 */ |
| 150 _onSuggestionsShownForTest: function(suggestions) { }, | 193 _onSuggestionsShownForTest: function(suggestions) { }, |
| 151 | 194 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 applySuggestion: function(suggestion, isIntermediateSuggestion) | 230 applySuggestion: function(suggestion, isIntermediateSuggestion) |
| 188 { | 231 { |
| 189 this._currentSuggestion = suggestion; | 232 this._currentSuggestion = suggestion; |
| 190 }, | 233 }, |
| 191 | 234 |
| 192 /** | 235 /** |
| 193 * @override | 236 * @override |
| 194 */ | 237 */ |
| 195 acceptSuggestion: function() | 238 acceptSuggestion: function() |
| 196 { | 239 { |
| 240 if (!this._prefixRange) | |
| 241 return; | |
| 242 | |
| 197 if (this._prefixRange.endColumn - this._prefixRange.startColumn === this ._currentSuggestion.length) | 243 if (this._prefixRange.endColumn - this._prefixRange.startColumn === this ._currentSuggestion.length) |
| 198 return; | 244 return; |
| 199 | 245 |
| 200 var selections = this._codeMirror.listSelections().slice(); | 246 var selections = this._codeMirror.listSelections().slice(); |
| 201 var prefixLength = this._prefixRange.endColumn - this._prefixRange.start Column; | 247 var prefixLength = this._prefixRange.endColumn - this._prefixRange.start Column; |
| 202 for (var i = selections.length - 1; i >= 0; --i) { | 248 for (var i = selections.length - 1; i >= 0; --i) { |
| 203 var start = selections[i].head; | 249 var start = selections[i].head; |
| 204 var end = new CodeMirror.Pos(start.line, start.ch - prefixLength); | 250 var end = new CodeMirror.Pos(start.line, start.ch - prefixLength); |
| 205 this._codeMirror.replaceRange(this._currentSuggestion, start, end, " +autocomplete"); | 251 this._codeMirror.replaceRange(this._currentSuggestion, start, end, " +autocomplete"); |
| 206 } | 252 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 217 if (cursor.line < topmostLineNumber || cursor.line > bottomLine) | 263 if (cursor.line < topmostLineNumber || cursor.line > bottomLine) |
| 218 this.finishAutocomplete(); | 264 this.finishAutocomplete(); |
| 219 else { | 265 else { |
| 220 this._updateAnchorBox(); | 266 this._updateAnchorBox(); |
| 221 this._suggestBox.setPosition(this._anchorBox); | 267 this._suggestBox.setPosition(this._anchorBox); |
| 222 } | 268 } |
| 223 }, | 269 }, |
| 224 | 270 |
| 225 _onCursorActivity: function() | 271 _onCursorActivity: function() |
| 226 { | 272 { |
| 227 if (!this._suggestBox) | 273 if (!(this._suggestBox && this._prefixRange)) |
| 228 return; | 274 return; |
| 229 var cursor = this._codeMirror.getCursor(); | 275 var cursor = this._codeMirror.getCursor(); |
| 230 if (cursor.line !== this._prefixRange.startLine || cursor.ch > this._pre fixRange.endColumn || cursor.ch <= this._prefixRange.startColumn) | 276 if (cursor.line !== this._prefixRange.startLine || cursor.ch > this._pre fixRange.endColumn || cursor.ch <= this._prefixRange.startColumn) |
| 231 this.finishAutocomplete(); | 277 this.finishAutocomplete(); |
| 232 }, | 278 }, |
| 233 | 279 |
| 234 _updateAnchorBox: function() | 280 _updateAnchorBox: function() |
| 235 { | 281 { |
| 282 if (!this._prefixRange) return; | |
| 236 var line = this._prefixRange.startLine; | 283 var line = this._prefixRange.startLine; |
| 237 var column = this._prefixRange.startColumn; | 284 var column = this._prefixRange.startColumn; |
| 238 var metrics = this._textEditor.cursorPositionToCoordinates(line, column) ; | 285 var metrics = this._textEditor.cursorPositionToCoordinates(line, column) ; |
| 239 this._anchorBox = metrics ? new AnchorBox(metrics.x, metrics.y, 0, metri cs.height) : null; | 286 this._anchorBox = metrics ? new AnchorBox(metrics.x, metrics.y, 0, metri cs.height) : null; |
| 240 }, | 287 }, |
| 241 } | 288 } |
| 242 | 289 |
| 243 /** | 290 /** |
| 244 * @interface | 291 * @interface |
| 245 */ | 292 */ |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 { | 387 { |
| 341 return dictionary.wordCount(b) - dictionary.wordCount(a) || a.length - b.length; | 388 return dictionary.wordCount(b) - dictionary.wordCount(a) || a.length - b.length; |
| 342 } | 389 } |
| 343 | 390 |
| 344 function excludeFilter(excludeWord, word) | 391 function excludeFilter(excludeWord, word) |
| 345 { | 392 { |
| 346 return word !== excludeWord; | 393 return word !== excludeWord; |
| 347 } | 394 } |
| 348 } | 395 } |
| 349 } | 396 } |
| OLD | NEW |