From 7b997f8a7053edaa7d6c609634272c95ec962be5 Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Thu, 11 Feb 2021 21:08:31 +0100 Subject: [PATCH 1/4] Fix forwardRegex to correctly return class names before double colons With the buffer position on the class name followed by a scope resolution operator "::" getFullWordFromBufferPosition would select the whole expression; but a later goto would then only look at the member part and wrongfully try andgo to that member instead of the class definition: MyClass::class ^-- Buffer position here * getFullWordFromBufferPosition returns "MyClass::class" * goto tries to go to member "class" of class MyClass and fails Adding the colon to forwardRegex will return only the class name instead if buffer position is before the scope resolution operator but not if after: MyClass::class ^-- getFullWordFromBufferPosition now returns "MyClass" MyClass::class ^-- but here still returns "MyClass::class" --- lib/services/php-file-parser.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/php-file-parser.coffee b/lib/services/php-file-parser.coffee index 8514375..b13a7d6 100644 --- a/lib/services/php-file-parser.coffee +++ b/lib/services/php-file-parser.coffee @@ -800,7 +800,7 @@ module.exports = foundEnd = false startBufferPosition = [] endBufferPosition = [] - forwardRegex = /-|(?:\()[\w\[\$\(\\]|\s|\)|;|'|,|"|\|/ + forwardRegex = /-|(?:\()[\w\[\$\(\\]|\s|\)|;|'|,|"|:|\|/ backwardRegex = /\(|\s|\)|;|'|,|"|\|/ index = -1 previousText = '' From a9ba0253d6338290b00d6c54bc5b10e6ed0dcde0 Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Sun, 14 Feb 2021 22:28:25 +0100 Subject: [PATCH 2/4] Always prefer exact matches for autocompletion This will sort suggestions containing exact matches of the search prefix first providing a better quality of suggestions --- lib/autocompletion/class-provider.coffee | 9 +++++++++ lib/autocompletion/constant-provider.coffee | 9 +++++++++ lib/autocompletion/function-provider.coffee | 8 ++++++++ lib/autocompletion/member-provider.coffee | 9 +++++++++ lib/autocompletion/variable-provider.coffee | 9 +++++++++ 5 files changed, 44 insertions(+) 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 From 2e521fa5a80e684aa30be1b5a1f076bd7e893ad2 Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Sun, 14 Feb 2021 22:39:58 +0100 Subject: [PATCH 3/4] Remove duplicate variable suggestions getAllVariablesInFunction returns every variable used in a function so far which willl then be used for autocompletion suggestions. But with variables used mulitple times in the function they will appear as duplicates in the suggestions. To fix this this now returns a list of unique variable names. --- lib/services/php-file-parser.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/services/php-file-parser.coffee b/lib/services/php-file-parser.coffee index b13a7d6..6126630 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 ###* From 3920a433db8843aade663597d989e540acabde28 Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Mon, 15 Feb 2021 14:32:40 +0100 Subject: [PATCH 4/4] Fix detection of isInFunction Changes made to the language-php syntax package broke the detection of opening and closing code blocks resulting in isInFunction always returning false --- lib/services/php-file-parser.coffee | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/services/php-file-parser.coffee b/lib/services/php-file-parser.coffee index 6126630..f91981e 100644 --- a/lib/services/php-file-parser.coffee +++ b/lib/services/php-file-parser.coffee @@ -336,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 @@ -348,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