Comments (4)
The way the completion item is inserted is not a subject of interpretation of the client but it is specified by the server. The client's job is just to apply it.
[Trace - 09:55:20 ] Received response 'textDocument/completion - (307)' in 45ms.
Result: {
"isIncomplete": null,
"items": [
{
"detail": "int",
"filterText": "uniqueVariableName",
"insertText": "uniqueVariableName",
"insertTextFormat": 1,
"kind": 6,
"label": "uniqueVariableName",
"score": 3.8985373973846436,
"sortText": "3f867e5duniqueVariableName",
"textEdit": {
"newText": "uniqueVariableName",
"range": {
"end": {
"character": 8,
"line": 3
},
"start": {
"character": 2,
"line": 3
}
}
}
}
]
}
As you can see from the range sent from the server to the client we are supposed to insert, not override.
OTH in order to support the case the spec supports using InsertReplaceEdit which then the client can depending of user prefs decide what to use: Here it is how it looks like in JDTLS:
[Trace - 09:58:18 ] Received response 'completionItem/resolve - (481)' in 21ms.
Result: {
"label": "uniqueVariableName : int",
"kind": 6,
"sortText": "999999161",
"insertText": "uniqueVariableName",
"insertTextFormat": 2,
"textEdit": {
"newText": "uniqueVariableName",
"insert": {
"start": {
"line": 50,
"character": 8
},
"end": {
"line": 50,
"character": 14
}
},
"replace": {
"start": {
"line": 50,
"character": 8
},
"end": {
"line": 50,
"character": 18
}
}
},
"command": {
"title": "",
"command": "java.completion.onDidSelect",
"arguments": [
"18",
"0"
]
}
}
AFAICS clangd does not support this new protocol feature.
from lsp-mode.
What should happen, if the language server doesn't provide textEdit
? Is lsp-mode written in way that if only insertText
exists, then lsp-mode has the behavior I described in the first comment? I'm asking because I tried to remove textEdit
handling in lsp-mode (in lsp-completion--guess-prefix
and lsp-completion--exit-fn
), but the behavior didn't change.
Regarding this new protocol feature: if replace
was just strictly an addition to the protocol, we could say that lsp-mode could have a mode, where if the language server didn't provide replace
, then lsp-mode tries to figure out replace
by itself. Something like: by default it's the same range as insert
, but if the conditions allows it, lsp-mode could extend the region so we can get the behavior I described.
from lsp-mode.
What should happen, if the language server doesn't provide textEdit?
AFAIC is should be the same.
then lsp-mode tries to figure out replace
Tehnically this can be implemented as an optional feature.
from lsp-mode.
I managed to achieve what I want, I modified lsp-completion-at-point
to return the end of the symbol instead of (point)
(I mean the second element of the list), and I removed text-edit handling from lsp-completion--exit-fn
. The only drawback I noticed so far is that words won't complete if the cursor is in the middle of a word and the completion needs a different ending. So, for example, if the buffer has "uniqueVariableFunc", and the cursor is at "F", then completion won't happen to "uniqueVariableName". But eglot somehow still manages to complete in this case, so I think this approach can be developed further.
Of course, for other language servers, this approach may cause serious drawbacks, I don't know. But still, I think it would be a good thing if lsp-mode had something like this. Capf in other modes work like this, lsp-mode is an exception.
Anyways, feel free to close this issue, I just wanted to raise this point.
from lsp-mode.
Related Issues (20)
- semgrep-ls has exited (exited abnormally with code 2) HOT 2
- [lsp-volar] Does not seem to work with new v2 vue-language-server HOT 2
- `lsp-clients-extract-signature-on-hover` insufficient in a lot of modes
- Minor doc problems / grammar issues
- `csharp-ls` can not be found HOT 9
- Error With Python LSP Server Progress Reporting HOT 1
- lsp-mode using shell-file-name for TRAMP connections
- lsp-nix completions dont work HOT 4
- lsp-mode won't start `invalid-function lsp-ht` HOT 7
- Client settings cannot be overridden
- `lsp-completion-at-point` short-circuits the completion function chain HOT 2
- Unwanted Automatic Start of Common Lisp's LSP HOT 2
- wrong type argument in lsp-file-process-event for rust-analyzer HOT 3
- Make loading yasnippet lazier HOT 2
- lsp-cucumber.el compilation warnings HOT 1
- Create a new tag. HOT 8
- Completions disappear after dot + symbol HOT 1
- Random regressions due to lsp overriding user settings via `lsp-register-custom-settings` HOT 1
- LSP-clangd repeatedly crash after loading pytorch source code HOT 1
- User-facing way to modify `:activation-fn` or `:major-modes`, and `initialization-options` of an existing LSP client.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lsp-mode.