This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Replace raw lexer code with token buffer in prepare rename.
ClosedPublic

Authored by hokein on Jan 29 2020, 1:21 AM.

Details

Summary

there is a slight behavior change in this patch:

  • before: in^t a;, returns our internal error message (no symbol at given location)
  • after: `in^t a, returns null, and client displays their message (e.g. e.g. "the element can't be renamed" in vscode).

both are sensible according LSP, and we'd save one rename call in the later case.

Diff Detail

Event Timeline

hokein created this revision.Jan 29 2020, 1:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 29 2020, 1:21 AM

Unit tests: pass. 62257 tests passed, 0 failed and 827 were skipped.

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

Nice, thanks!

clang-tools-extra/clangd/ClangdServer.cpp
321

Agree that this behavior is OK per the spec, but do we actually prefer it/why the change?

Seems like clients are marginally more likely to handle null incorrectly/silently, and we give up control over the message.

323

this runs the lexer to compute token boundaries. We actually already have them: syntax::Token has endLocation/length

clang-tools-extra/clangd/SourceCode.h
302

I don't think this function improves things vs keeping it inline:

  • wrapping clang functions to adapt them to our data types doesn't seem sustainable
  • it's hard to draw the line, but this one neither hides logic (saves 2 trivial lines) nor is very commonly used (yet)
  • this breaks a (minor) error-handling path: an invalid range is no longer reported to the client as an error
hokein updated this revision to Diff 241095.Jan 29 2020, 3:31 AM
hokein marked 4 inline comments as done.

address comments

hokein updated this revision to Diff 241096.Jan 29 2020, 3:32 AM

revert an accident change.

hokein added inline comments.Jan 29 2020, 3:33 AM
clang-tools-extra/clangd/ClangdServer.cpp
321

Agree that this behavior is OK per the spec, but do we actually prefer it/why the change?

I checked with VSCode, it seems fine (the element can't be renamed), and YCM (but it doesn't support prepare rename yet). Are you suggesting that we return our message here?

323

removed it.

sammccall accepted this revision.Jan 29 2020, 3:39 AM
sammccall added inline comments.
clang-tools-extra/clangd/ClangdServer.cpp
321

Doh, I had this confused with rename where the spec is more ambiguous (and e.g. eglot doesn't handle null well). Nevermind.

This revision is now accepted and ready to land.Jan 29 2020, 3:39 AM

Unit tests: pass. 62257 tests passed, 0 failed and 827 were skipped.

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

This revision was automatically updated to reflect the committed changes.

Unit tests: pass. 62257 tests passed, 0 failed and 827 were skipped.

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.