diff --git a/lib/autocompletion/class-provider.coffee b/lib/autocompletion/class-provider.coffee index 5bcbd37..e21a495 100644 --- a/lib/autocompletion/class-provider.coffee +++ b/lib/autocompletion/class-provider.coffee @@ -115,6 +115,15 @@ class ClassProvider extends AbstractProvider prefix: prefix, replacementPrefix: prefix + suggestions = suggestions.sort (a, b) -> + if a.text.includes prefix + return -1 + + if b.text.includes prefix + return 1 + + return 0 + return suggestions ###* diff --git a/lib/autocompletion/constant-provider.coffee b/lib/autocompletion/constant-provider.coffee index aba6e1e..284ea45 100644 --- a/lib/autocompletion/constant-provider.coffee +++ b/lib/autocompletion/constant-provider.coffee @@ -48,4 +48,13 @@ class ConstantProvider extends AbstractProvider type: 'constant', description: 'Built-in PHP constant.' + suggestions = suggestions.sort (a, b) -> + if a.text.includes prefix + return -1 + + if b.text.includes prefix + return 1 + + return 0 + return suggestions diff --git a/lib/autocompletion/function-provider.coffee b/lib/autocompletion/function-provider.coffee index 6fc4995..a097ac4 100644 --- a/lib/autocompletion/function-provider.coffee +++ b/lib/autocompletion/function-provider.coffee @@ -67,5 +67,13 @@ class FunctionProvider extends AbstractProvider suggestions.push suggestion + suggestions = suggestions.sort (a, b) -> + if a.text.includes prefix + return -1 + + if b.text.includes prefix + return 1 + + return 0 return suggestions diff --git a/lib/autocompletion/member-provider.coffee b/lib/autocompletion/member-provider.coffee index 498396e..27343f8 100644 --- a/lib/autocompletion/member-provider.coffee +++ b/lib/autocompletion/member-provider.coffee @@ -121,4 +121,13 @@ class MemberProvider extends AbstractProvider description : if ele.args.descriptions.short? then ele.args.descriptions.short else '' className : if ele.args.deprecated then 'php-atom-autocomplete-strike' else '' + suggestions = suggestions.sort (a, b) -> + if a.text.includes prefix + return -1 + + if b.text.includes prefix + return 1 + + return 0 + return suggestions diff --git a/lib/autocompletion/variable-provider.coffee b/lib/autocompletion/variable-provider.coffee index 67764c1..83a5f76 100644 --- a/lib/autocompletion/variable-provider.coffee +++ b/lib/autocompletion/variable-provider.coffee @@ -44,4 +44,13 @@ class VariableProvider extends AbstractProvider type: 'variable', replacementPrefix: prefix + suggestions = suggestions.sort (a, b) -> + if a.text.includes prefix + return -1 + + if b.text.includes prefix + return 1 + + return 0 + return suggestions diff --git a/lib/services/php-file-parser.coffee b/lib/services/php-file-parser.coffee index 8514375..f91981e 100644 --- a/lib/services/php-file-parser.coffee +++ b/lib/services/php-file-parser.coffee @@ -58,6 +58,8 @@ module.exports = if isInFunction matches.push "$this" + matches = matches.filter (match, index) -> matches.indexOf(match) == index + return matches ###* @@ -334,6 +336,7 @@ module.exports = character = 0 lineLength = line.length lastChain = null + inFunction = false # Scan the entire line, fetching the scope for each character position as one line can contain both a scope start # and end such as "} elseif (true) {". Here the scope descriptor will differ for different character positions on @@ -346,20 +349,20 @@ module.exports = # scanning line.length as sometimes line.length - 1 does not return a scope descriptor at all. if not (character == line.length and chain == lastChain) # } - if chain.indexOf("scope.end") != -1 + if chain.indexOf("punctuation.definition.end.bracket.curly.php") != -1 closedBlocks++ # { - else if chain.indexOf("scope.begin") != -1 + else if chain.indexOf("punctuation.definition.begin.bracket.curly.php") != -1 openedBlocks++ + if chain.indexOf(".entity.name.function.php") != -1 + inFunction = true + lastChain = chain character++ - # Get chain of all scopes - chain = editor.scopeDescriptorForBufferPosition([row, line.length]).getScopeChain() - # function - if chain.indexOf("function") != -1 + if inFunction # If more openedblocks than closedblocks, we are in a function. Otherwise, could be a closure, continue looking. if openedBlocks > closedBlocks result = true @@ -800,7 +803,7 @@ module.exports = foundEnd = false startBufferPosition = [] endBufferPosition = [] - forwardRegex = /-|(?:\()[\w\[\$\(\\]|\s|\)|;|'|,|"|\|/ + forwardRegex = /-|(?:\()[\w\[\$\(\\]|\s|\)|;|'|,|"|:|\|/ backwardRegex = /\(|\s|\)|;|'|,|"|\|/ index = -1 previousText = ''