| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 WebInspector.JavaScriptAutocomplete = {}; | 5 WebInspector.JavaScriptAutocomplete = {}; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @param {!Element} proxyElement | 8 * @param {!Element} proxyElement |
| 9 * @param {!Range} wordRange | 9 * @param {!Range} wordRange |
| 10 * @param {boolean} force | 10 * @param {boolean} force |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 index--; | 49 index--; |
| 50 } | 50 } |
| 51 clippedExpression = clippedExpression.substring(index + 1); | 51 clippedExpression = clippedExpression.substring(index + 1); |
| 52 | 52 |
| 53 return WebInspector.JavaScriptAutocomplete.completionsForExpression(clippedExp
ression, query, force); | 53 return WebInspector.JavaScriptAutocomplete.completionsForExpression(clippedExp
ression, query, force); |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 | 56 |
| 57 /** | 57 /** |
| 58 * @param {string} expressionString | 58 * @param {string} expressionString |
| 59 * @param {string} prefix | 59 * @param {string} query |
| 60 * @param {boolean=} force | 60 * @param {boolean=} force |
| 61 * @return {!Promise<!Array<string>>} | 61 * @return {!Promise<!Array<string>>} |
| 62 */ | 62 */ |
| 63 WebInspector.JavaScriptAutocomplete.completionsForExpression = function(expressi
onString, prefix, force) { | 63 WebInspector.JavaScriptAutocomplete.completionsForExpression = function(expressi
onString, query, force) { |
| 64 var executionContext = WebInspector.context.flavor(WebInspector.ExecutionConte
xt); | 64 var executionContext = WebInspector.context.flavor(WebInspector.ExecutionConte
xt); |
| 65 if (!executionContext) | 65 if (!executionContext) |
| 66 return Promise.resolve([]); | 66 return Promise.resolve([]); |
| 67 | 67 |
| 68 var lastIndex = expressionString.length - 1; | 68 var lastIndex = expressionString.length - 1; |
| 69 | 69 |
| 70 var dotNotation = (expressionString[lastIndex] === '.'); | 70 var dotNotation = (expressionString[lastIndex] === '.'); |
| 71 var bracketNotation = (expressionString[lastIndex] === '['); | 71 var bracketNotation = (expressionString[lastIndex] === '['); |
| 72 | 72 |
| 73 if (dotNotation || bracketNotation) | 73 if (dotNotation || bracketNotation) |
| 74 expressionString = expressionString.substr(0, lastIndex); | 74 expressionString = expressionString.substr(0, lastIndex); |
| 75 | 75 |
| 76 // User is entering float value, do not suggest anything. | 76 // User is entering float value, do not suggest anything. |
| 77 if (expressionString && !isNaN(expressionString)) | 77 if (expressionString && !isNaN(expressionString)) |
| 78 return Promise.resolve([]); | 78 return Promise.resolve([]); |
| 79 | 79 |
| 80 if (!prefix && !expressionString && !force) | 80 if (!query && !expressionString && !force) |
| 81 return Promise.resolve([]); | 81 return Promise.resolve([]); |
| 82 | 82 |
| 83 var fufill; | 83 var fufill; |
| 84 var promise = new Promise(x => fufill = x); | 84 var promise = new Promise(x => fufill = x); |
| 85 if (!expressionString && executionContext.debuggerModel.selectedCallFrame()) | 85 if (!expressionString && executionContext.debuggerModel.selectedCallFrame()) |
| 86 executionContext.debuggerModel.selectedCallFrame().variableNames(receivedPro
pertyNames); | 86 executionContext.debuggerModel.selectedCallFrame().variableNames(receivedPro
pertyNames); |
| 87 else | 87 else |
| 88 executionContext.evaluate(expressionString, 'completion', true, true, false,
false, false, evaluated); | 88 executionContext.evaluate(expressionString, 'completion', true, true, false,
false, false, evaluated); |
| 89 | 89 |
| 90 return promise; | 90 return promise; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 'monitor', | 216 'monitor', |
| 217 'unmonitor', | 217 'unmonitor', |
| 218 'table', | 218 'table', |
| 219 '$', | 219 '$', |
| 220 '$$', | 220 '$$', |
| 221 '$x' | 221 '$x' |
| 222 ]; | 222 ]; |
| 223 for (var i = 0; i < commandLineAPI.length; ++i) | 223 for (var i = 0; i < commandLineAPI.length; ++i) |
| 224 propertyNames[commandLineAPI[i]] = true; | 224 propertyNames[commandLineAPI[i]] = true; |
| 225 } | 225 } |
| 226 fufill(WebInspector.JavaScriptAutocomplete._completionsForPrefix( | 226 fufill(WebInspector.JavaScriptAutocomplete._completionsForQuery( |
| 227 dotNotation, bracketNotation, expressionString, prefix, Object.keys(proper
tyNames))); | 227 dotNotation, bracketNotation, expressionString, query, Object.keys(propert
yNames))); |
| 228 } | 228 } |
| 229 }; | 229 }; |
| 230 | 230 |
| 231 /** | 231 /** |
| 232 * @param {boolean} dotNotation | 232 * @param {boolean} dotNotation |
| 233 * @param {boolean} bracketNotation | 233 * @param {boolean} bracketNotation |
| 234 * @param {string} expressionString | 234 * @param {string} expressionString |
| 235 * @param {string} prefix | 235 * @param {string} query |
| 236 * @param {!Array.<string>} properties | 236 * @param {!Array.<string>} properties |
| 237 * @return {!Array<string>} | 237 * @return {!Array<string>} |
| 238 */ | 238 */ |
| 239 WebInspector.JavaScriptAutocomplete._completionsForPrefix = function(dotNotation
, bracketNotation, expressionString, prefix, properties) { | 239 WebInspector.JavaScriptAutocomplete._completionsForQuery = function(dotNotation,
bracketNotation, expressionString, query, properties) { |
| 240 if (bracketNotation) { | 240 if (bracketNotation) { |
| 241 if (prefix.length && prefix[0] === '\'') | 241 if (query.length && query[0] === '\'') |
| 242 var quoteUsed = '\''; | 242 var quoteUsed = '\''; |
| 243 else | 243 else |
| 244 var quoteUsed = '"'; | 244 var quoteUsed = '"'; |
| 245 } | 245 } |
| 246 | 246 |
| 247 var results = []; | |
| 248 | |
| 249 if (!expressionString) { | 247 if (!expressionString) { |
| 250 const keywords = [ | 248 const keywords = [ |
| 251 'break', 'case', 'catch', 'continue', 'default', 'delete', 'do', 'else', '
finally', | 249 'break', 'case', 'catch', 'continue', 'default', 'delete', 'do', 'else', '
finally', |
| 252 'for', 'function', 'if', 'in', 'instanceof', 'new', 'return', 'switch', 't
his', | 250 'for', 'function', 'if', 'in', 'instanceof', 'new', 'return', 'switch', 't
his', |
| 253 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with' | 251 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with' |
| 254 ]; | 252 ]; |
| 255 properties = properties.concat(keywords); | 253 properties = properties.concat(keywords); |
| 256 } | 254 } |
| 257 | 255 |
| 258 properties.sort(); | 256 properties.sort(); |
| 259 | 257 |
| 258 var caseSensitivePrefix = []; |
| 259 var caseInsensitivePrefix = []; |
| 260 var caseSensitiveAnywhere = []; |
| 261 var caseInsensitiveAnywhere = []; |
| 260 for (var i = 0; i < properties.length; ++i) { | 262 for (var i = 0; i < properties.length; ++i) { |
| 261 var property = properties[i]; | 263 var property = properties[i]; |
| 262 | 264 |
| 263 // Assume that all non-ASCII characters are letters and thus can be used as
part of identifier. | 265 // Assume that all non-ASCII characters are letters and thus can be used as
part of identifier. |
| 264 if (dotNotation && !/^[a-zA-Z_$\u008F-\uFFFF][a-zA-Z0-9_$\u008F-\uFFFF]*$/.t
est(property)) | 266 if (dotNotation && !/^[a-zA-Z_$\u008F-\uFFFF][a-zA-Z0-9_$\u008F-\uFFFF]*$/.t
est(property)) |
| 265 continue; | 267 continue; |
| 266 | 268 |
| 267 if (bracketNotation) { | 269 if (bracketNotation) { |
| 268 if (!/^[0-9]+$/.test(property)) | 270 if (!/^[0-9]+$/.test(property)) |
| 269 property = quoteUsed + property.escapeCharacters(quoteUsed + '\\') + quo
teUsed; | 271 property = quoteUsed + property.escapeCharacters(quoteUsed + '\\') + quo
teUsed; |
| 270 property += ']'; | 272 property += ']'; |
| 271 } | 273 } |
| 272 | 274 |
| 273 if (property.length < prefix.length) | 275 if (property.length < query.length) |
| 274 continue; | 276 continue; |
| 275 if (prefix.length && !property.startsWith(prefix)) | 277 if (query.length && property.toLowerCase().indexOf(query.toLowerCase()) ===
-1) |
| 276 continue; | 278 continue; |
| 279 // Substitute actual newlines with newline characters. @see crbug.com/498421 |
| 280 var prop = property.split('\n').join('\\n'); |
| 277 | 281 |
| 278 // Substitute actual newlines with newline characters. @see crbug.com/498421 | 282 if (property.startsWith(query)) |
| 279 results.push(property.split('\n').join('\\n')); | 283 caseSensitivePrefix.push(prop); |
| 284 else if (property.toLowerCase().startsWith(query.toLowerCase())) |
| 285 caseInsensitivePrefix.push(prop); |
| 286 else if (property.indexOf(query) !== -1) |
| 287 caseSensitiveAnywhere.push(prop); |
| 288 else |
| 289 caseInsensitiveAnywhere.push(prop); |
| 280 } | 290 } |
| 281 return results; | 291 return caseSensitivePrefix.concat(caseInsensitivePrefix).concat(caseSensitiveA
nywhere).concat(caseInsensitiveAnywhere); |
| 282 }; | 292 }; |
| OLD | NEW |