mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 15:48:11 -05:00
- Limit when this autocompletion can pop up.
- Remove some left over cruft from the text completer.
This commit is contained in:
parent
5d09e219c0
commit
228019ac89
2 changed files with 34 additions and 10 deletions
|
@ -122,16 +122,36 @@ module.exports = (SnippetManager, autoLineEndings) ->
|
|||
# meta: displayed right-justfied in popup
|
||||
lang = session.getMode()?.$id?.substr 'ace/mode/'.length
|
||||
line = session.getLine pos.row
|
||||
completions = []
|
||||
|
||||
#If the prefix is a reserved word, don't autocomplete
|
||||
#If the prefix is a member expression, supress completions
|
||||
fullPrefix = getFullIdentifier session, pos
|
||||
fullPrefixParts = fullPrefix.split /[.:]/g
|
||||
word = getCurrentWord session, pos
|
||||
|
||||
if fullPrefixParts.length > 2
|
||||
@completions = []
|
||||
return callback null, completions
|
||||
|
||||
beginningOfLine = session.getLine(pos.row).substring(0,pos.column - prefix.length)
|
||||
|
||||
unless (fullPrefixParts.length < 3 and /^(hero|self|this|@)$/.test(fullPrefixParts[0]) ) or /^\s*$/.test(beginningOfLine)
|
||||
console.log "Bailing", fullPrefixParts, '|', prefix, '|', beginningOfLine, '|', pos.column - prefix.length
|
||||
@completions = completions
|
||||
return callback null, completions
|
||||
|
||||
#If the prefix is a reserved word, make enter just complete it
|
||||
keywords = session.getMode()?.$highlightRules?.$keywordList
|
||||
if keywords and prefix in keywords
|
||||
@completions = []
|
||||
return callback null, @completions
|
||||
completions.push
|
||||
content: prefix
|
||||
caption: prefix
|
||||
snippet: prefix + "\n"
|
||||
score: 100
|
||||
meta: '\u21E5'
|
||||
|
||||
word = getCurrentWord session, pos
|
||||
snippetMap = SnippetManager.snippetMap
|
||||
completions = []
|
||||
|
||||
SnippetManager.getActiveScopes(editor).forEach (scope) ->
|
||||
snippets = snippetMap[scope] or []
|
||||
for s in snippets
|
||||
|
@ -167,6 +187,14 @@ getCurrentWord = (doc, pos) ->
|
|||
start++ if start >= 0
|
||||
text.substring start, end
|
||||
|
||||
getFullIdentifier = (doc, pos) ->
|
||||
end = pos.column
|
||||
start = end - 1
|
||||
text = doc.getLine(pos.row)
|
||||
start-- while start >= 0 and not text[start].match /\s+/
|
||||
start++ if start >= 0
|
||||
text.substring start, end
|
||||
|
||||
scrubSnippet = (snippet, caption, line, input, pos, lang, autoLineEndings, captureReturn) ->
|
||||
# console.log "Zatanna snippet=#{snippet} caption=#{caption} line=#{line} input=#{input} pos.column=#{pos.column} lang=#{lang}"
|
||||
fuzzScore = 0.1
|
||||
|
|
|
@ -11,9 +11,7 @@ defaults =
|
|||
language: 'javascript'
|
||||
languagePrefixes: 'this.,@,self.'
|
||||
completers:
|
||||
keywords: true
|
||||
snippets: true
|
||||
text: true
|
||||
|
||||
|
||||
|
||||
|
@ -87,8 +85,6 @@ module.exports = class Zatanna
|
|||
@completers.snippets = pos: 0
|
||||
# Replace the default snippet completer with our custom one
|
||||
@completers.snippets.comp = require('./snippets') @snippetManager, @options.autoLineEndings
|
||||
if @options.completers.keywords
|
||||
@completers.keywords = pos: 1
|
||||
|
||||
activateCompleter: (comp) ->
|
||||
if Array.isArray comp
|
||||
|
@ -159,7 +155,7 @@ module.exports = class Zatanna
|
|||
|
||||
doLiveCompletion: (e) =>
|
||||
# console.log 'Zatanna doLiveCompletion', e
|
||||
return unless @options.basic or @options.liveCompletion or @options.completers.snippets or @options.completers.text
|
||||
return unless @options.basic or @options.liveCompletion or @options.completers.snippets
|
||||
return if @paused
|
||||
|
||||
TokenIterator = TokenIterator or ace.require('ace/token_iterator').TokenIterator
|
||||
|
|
Loading…
Reference in a new issue