Commit 69863238 authored by Gert's avatar Gert

Fix completion suggestions not properly escaping backslashes

This fixes the Atom languageclient library removing backslashes when 
inserting the text from the textEdit, which was correct, since it wasn't 
escaped, but not intended.
parent 25affbb5
Pipeline #66444808 passed with stages
in 3 minutes and 35 seconds
......@@ -8,6 +8,7 @@
* [Fix crash when analyzing erroneous code containing multiple object arrows, such as `$test->->`](https://gitlab.com/Serenata/Serenata/issues/245)
* [Stub `textDocument/didOpen`](https://gitlab.com/Serenata/Serenata/issues/253)
* [Stub `textDocument/didClose`](https://gitlab.com/Serenata/Serenata/issues/259)
* Fix `textEdit` and `insertText` generated for completion suggestions not having backslashes properly escaped, as per spec (for edits bearing an `insertTextFormat` of `Snippet`, the backslash is itself an escape character)
* Fix classlike autocompletion suggestions being given after `use function` and `use const`
* Return `CompletionList` as response to `textDocument/completion`
* Sets `isIncomplete` to `true` instead of `false` (the default), preventing clients from caching completion results at some positions and trying to apply their on filtering on top of that, whilst the actual results are different, which resulted in completion seemingly not responding.
......
......@@ -176,7 +176,7 @@ final class ClasslikeAutocompletionProvider implements AutocompletionProviderInt
// Don't try to add use statements for class names that the user wants to make absolute by adding a leading
// slash.
return implode('\\', array_slice($parts, -$partsToSlice - 1));
return str_replace('\\', '\\\\', implode('\\', array_slice($parts, -$partsToSlice - 1)));
}
/**
......
......@@ -188,7 +188,7 @@ final class ConstantAutocompletionProvider implements AutocompletionProviderInte
$insertText = implode('\\', array_slice($parts, -$partsToSlice - 1));
}
return $insertText;
return str_replace('\\', '\\\\', $insertText);
}
/**
......
......@@ -238,7 +238,7 @@ final class FunctionAutocompletionProvider implements AutocompletionProviderInte
}
}
return $insertText;
return str_replace('\\', '\\\\', $insertText);
}
/**
......
......@@ -125,6 +125,9 @@ final class NamespaceAutocompletionProvider implements AutocompletionProviderInt
*/
private function getTextEditForSuggestion(array $namespace, AutocompletionProviderContext $context): TextEdit
{
return new TextEdit($context->getPrefixRange(), $namespace['name']);
return new TextEdit(
$context->getPrefixRange(),
str_replace('\\', '\\\\', $namespace['name'])
);
}
}
......@@ -115,10 +115,10 @@ class ConstantAutocompletionProviderTest extends AbstractAutocompletionProviderT
new CompletionItem(
'\Foo\Bar\BAZ',
CompletionItemKind::CONSTANT,
'Bar\BAZ',
'Bar\\\\BAZ',
new TextEdit(
new Range(new Position(7, 4), new Position(7, 8)),
'Bar\BAZ'
'Bar\\\\BAZ'
),
'Foo\Bar\BAZ',
null,
......@@ -147,10 +147,10 @@ class ConstantAutocompletionProviderTest extends AbstractAutocompletionProviderT
new CompletionItem(
'\Foo\Bar\BAZ',
CompletionItemKind::CONSTANT,
'\Foo\Bar\BAZ',
'\\\\Foo\\\\Bar\\\\BAZ',
new TextEdit(
new Range(new Position(7, 4), new Position(7, 6)),
'\Foo\Bar\BAZ'
'\\\\Foo\\\\Bar\\\\BAZ'
),
'Foo\Bar\BAZ',
null,
......@@ -174,10 +174,10 @@ class ConstantAutocompletionProviderTest extends AbstractAutocompletionProviderT
new CompletionItem(
'\Foo\Bar\Baz\QUX',
CompletionItemKind::CONSTANT,
'Foo\Bar\Baz\QUX',
'Foo\\\\Bar\\\\Baz\\\\QUX',
new TextEdit(
new Range(new Position(7, 14), new Position(7, 21)),
'Foo\Bar\Baz\QUX'
'Foo\\\\Bar\\\\Baz\\\\QUX'
),
'Foo\Bar\Baz\QUX',
null,
......
......@@ -235,10 +235,10 @@ class FunctionAutocompletionProviderTest extends AbstractAutocompletionProviderT
new CompletionItem(
'\Foo\Bar\baz',
CompletionItemKind::FUNCTION,
'Bar\baz()$0',
'Bar\\\\baz()$0',
new TextEdit(
new Range(new Position(10, 4), new Position(10, 8)),
'Bar\baz()$0'
'Bar\\\\baz()$0'
),
'Foo\Bar\baz()',
null,
......@@ -267,10 +267,10 @@ class FunctionAutocompletionProviderTest extends AbstractAutocompletionProviderT
new CompletionItem(
'\Foo\Bar\baz',
CompletionItemKind::FUNCTION,
'\Foo\Bar\baz()$0',
'\\\\Foo\\\\Bar\\\\baz()$0',
new TextEdit(
new Range(new Position(10, 4), new Position(10, 6)),
'\Foo\Bar\baz()$0'
'\\\\Foo\\\\Bar\\\\baz()$0'
),
'Foo\Bar\baz()',
null,
......@@ -294,10 +294,10 @@ class FunctionAutocompletionProviderTest extends AbstractAutocompletionProviderT
new CompletionItem(
'\Foo\Bar\Baz\qux',
CompletionItemKind::FUNCTION,
'Foo\Bar\Baz\qux',
'Foo\\\\Bar\\\\Baz\\\\qux',
new TextEdit(
new Range(new Position(10, 17), new Position(10, 24)),
'Foo\Bar\Baz\qux'
'Foo\\\\Bar\\\\Baz\\\\qux'
),
'Foo\Bar\Baz\qux()',
null,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment