2018-02-06 18:47:30 +08:00
|
|
|
# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
|
2019-07-24 15:49:23 +08:00
|
|
|
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument": {"rename": {"dynamicRegistration": true, "prepareSupport": true}}},"trace":"off"}}
|
|
|
|
# CHECK: "renameProvider": {
|
|
|
|
# CHECK-NEXT: "prepareProvider": true
|
|
|
|
# CHECK-NEXT: },
|
2018-02-06 18:47:30 +08:00
|
|
|
---
|
|
|
|
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.cpp","languageId":"cpp","version":1,"text":"int foo;"}}}
|
|
|
|
---
|
2019-07-24 15:49:23 +08:00
|
|
|
{"jsonrpc":"2.0","id":1,"method":"textDocument/prepareRename","params":{"textDocument":{"uri":"test:///foo.cpp"},"position":{"line":0,"character":5}}}
|
2018-02-06 18:47:30 +08:00
|
|
|
# CHECK: "id": 1,
|
|
|
|
# CHECK-NEXT: "jsonrpc": "2.0",
|
|
|
|
# CHECK-NEXT: "result": {
|
2019-07-24 15:49:23 +08:00
|
|
|
# CHECK-NEXT: "end": {
|
|
|
|
# CHECK-NEXT: "character": 7,
|
|
|
|
# CHECK-NEXT: "line": 0
|
|
|
|
# CHECK-NEXT: },
|
|
|
|
# CHECK-NEXT: "start": {
|
|
|
|
# CHECK-NEXT: "character": 4,
|
|
|
|
# CHECK-NEXT: "line": 0
|
|
|
|
# CHECK-NEXT: }
|
|
|
|
# CHECK-NEXT: }
|
|
|
|
---
|
|
|
|
{"jsonrpc":"2.0","id":2,"method":"textDocument/prepareRename","params":{"textDocument":{"uri":"test:///foo.cpp"},"position":{"line":0,"character":2}}}
|
2020-10-02 22:01:25 +08:00
|
|
|
# CHECK: "error": {
|
|
|
|
# CHECK-NEXT: "code": -32001,
|
|
|
|
# CHECK-NEXT: "message": "Cannot rename symbol: there is no symbol at the given location"
|
|
|
|
# CHECK-NEXT: },
|
|
|
|
# CHECK-NEXT: "id": 2,
|
|
|
|
# CHECK-NEXT: "jsonrpc": "2.0"
|
2019-07-24 15:49:23 +08:00
|
|
|
---
|
|
|
|
{"jsonrpc":"2.0","id":4,"method":"textDocument/rename","params":{"textDocument":{"uri":"test:///foo.cpp"},"position":{"line":0,"character":2},"newName":"bar"}}
|
|
|
|
# CHECK: "error": {
|
|
|
|
# CHECK-NEXT: "code": -32001,
|
[clangd] Use raw rename functions to implement the rename.
Summary:
The API provided by refactoring lib doesn't provide enough flexibility
to get clangd's rename to behave as we expect. Instead, we replace it
with the low-level rename functions, which give us more control.
Bonus:
- performance, previously we visit the TU to find all occurrences,
now we just visit top-level decls from main file;
- fix a bug where we wrongly filter out the main file replacement due to the
different relative/absolute file path;
Reviewers: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, jfb, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D65936
llvm-svn: 368429
2019-08-09 18:55:22 +08:00
|
|
|
# CHECK-NEXT: "message": "Cannot rename symbol: there is no symbol at the given location"
|
2019-07-24 15:49:23 +08:00
|
|
|
# CHECK-NEXT: },
|
|
|
|
# CHECK-NEXT: "id": 4,
|
|
|
|
# CHECK-NEXT: "jsonrpc": "2.0"
|
|
|
|
---
|
|
|
|
{"jsonrpc":"2.0","id":3,"method":"textDocument/rename","params":{"textDocument":{"uri":"test:///foo.cpp"},"position":{"line":0,"character":5},"newName":"bar"}}
|
|
|
|
# CHECK: "id": 3,
|
|
|
|
# CHECK-NEXT: "jsonrpc": "2.0",
|
|
|
|
# CHECK-NEXT: "result": {
|
2018-02-06 18:47:30 +08:00
|
|
|
# CHECK-NEXT: "changes": {
|
|
|
|
# CHECK-NEXT: "file://{{.*}}/foo.cpp": [
|
|
|
|
# CHECK-NEXT: {
|
|
|
|
# CHECK-NEXT: "newText": "bar",
|
|
|
|
# CHECK-NEXT: "range": {
|
|
|
|
# CHECK-NEXT: "end": {
|
|
|
|
# CHECK-NEXT: "character": 7
|
|
|
|
# CHECK-NEXT: "line": 0
|
|
|
|
# CHECK-NEXT: },
|
|
|
|
# CHECK-NEXT: "start": {
|
|
|
|
# CHECK-NEXT: "character": 4
|
|
|
|
# CHECK-NEXT: "line": 0
|
|
|
|
# CHECK-NEXT: }
|
|
|
|
# CHECK-NEXT: }
|
|
|
|
# CHECK-NEXT: }
|
|
|
|
# CHECK-NEXT: ]
|
|
|
|
# CHECK-NEXT: }
|
|
|
|
# CHECK-NEXT: }
|
|
|
|
---
|
2019-07-24 15:49:23 +08:00
|
|
|
{"jsonrpc":"2.0","id":5,"method":"shutdown"}
|
2018-02-06 18:47:30 +08:00
|
|
|
---
|
[clangd] Fix unicode handling, using UTF-16 where LSP requires it.
Summary:
The Language Server Protocol unfortunately mandates that locations in files
be represented by line/column pairs, where the "column" is actually an index
into the UTF-16-encoded text of the line.
(This is because VSCode is written in JavaScript, which is UTF-16-native).
Internally clangd treats source files at UTF-8, the One True Encoding, and
generally deals with byte offsets (though there are exceptions).
Before this patch, conversions between offsets and LSP Position pretended
that Position.character was UTF-8 bytes, which is only true for ASCII lines.
Now we examine the text to convert correctly (but don't actually need to
transcode it, due to some nice details of the encodings).
The updated functions in SourceCode are the blessed way to interact with
the Position.character field, and anything else is likely to be wrong.
So I also updated the other accesses:
- CodeComplete needs a "clang-style" line/column, with column in utf-8 bytes.
This is now converted via Position -> offset -> clang line/column
(a new function is added to SourceCode.h for the second conversion).
- getBeginningOfIdentifier skipped backwards in UTF-16 space, which is will
behave badly when it splits a surrogate pair. Skipping backwards in UTF-8
coordinates gives the lexer a fighting chance of getting this right.
While here, I clarified(?) the logic comments, fixed a bug with identifiers
containing digits, simplified the signature slightly and added a test.
This seems likely to cause problems with editors that have the same bug, and
treat the protocol as if columns are UTF-8 bytes. But we can find and fix those.
Reviewers: hokein
Subscribers: klimek, ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D46035
llvm-svn: 331029
2018-04-27 19:59:28 +08:00
|
|
|
{"jsonrpc":"2.0","method":"exit"}
|