Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate text edit replacement range #213

Open
mniewrzal opened this issue Dec 12, 2016 · 4 comments
Open

Calculate text edit replacement range #213

mniewrzal opened this issue Dec 12, 2016 · 4 comments

Comments

@mniewrzal
Copy link
Contributor

Completion items returned by PHP language server are mostly missing text edit field. This field is very useful for client side to filter/insert completion. It also improves user experience a lot.

@felixfbecker I'm not sure if you plan to work with this in near future. If not maybe as an temporary solution we can use method I created for my old completion PR [1]. Its not perfect but should do the job.

[1] https://github.com/felixfbecker/php-language-server/pull/38/files#diff-5794964d5fd1d9db05834acbd6155f4dR48

@felixfbecker
Copy link
Owner

felixfbecker commented Dec 12, 2016

I had added this function as temporary solution: https://github.com/felixfbecker/php-language-server/blob/master/src/utils.php#L109
It takes two strings and strips away the overlap. However, it only works one way, it will only strip the overlapping prefix, not the overlapping suffix. It could be easily modified to also do the latter.

The best way in the future will be to simply use the range of the node under the cursor and replace that. But that depends on nikic/PHP-Parser#322, because things like a method name in a MethodCall node currently are not Nodes and don't have offset information.

I can revisit completion when https://github.com/felixfbecker/php-language-server/projects/2 are all closed

@mniewrzal
Copy link
Contributor Author

I had added this function as temporary solution: https://github.com/felixfbecker/php-language-server/blob/master/src/utils.php#L109

You are using stripStringOverlap method to calculate text for insertion but text edit range is always position of cursor. It will work with prefix but wont replace existing identifier. VSCode built-in servers like CSS or HTML are calculating range that will be used to replace and put always full completion item text. This is cleaner approach imho.

@felixfbecker
Copy link
Owner

Yes, as I said, it only works for a prefix. But it could be easily modified to emit a TextEdit instead

@felixfbecker
Copy link
Owner

felixfbecker commented Jan 17, 2017

textEdit has been deprecated in LSP v3, it is now insertText and range.
additionalTextEdits is for adding stuff like use statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants