This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Add basic keyword-name-validation in rename.
ClosedPublic

Authored by hokein on Oct 6 2020, 1:42 AM.

Diff Detail

Event Timeline

hokein created this revision.Oct 6 2020, 1:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2020, 1:42 AM
hokein requested review of this revision.Oct 6 2020, 1:42 AM
sammccall added inline comments.Oct 6 2020, 2:47 AM
clang-tools-extra/clangd/refactor/Rename.cpp
124

nit: not sure we need a separate section for these, I can imagine at most keyword/conflict/shadow

215

nit: either "reserved [word|identifier|name]" or "keyword", but not both

This could be friendlier, what about "the chosen name is a keyword"?

479

Now that prepareRename only exposes ranges rather than edits, do we still need this empty special case, or can we go back to using "clangd_rename_dummy" or so?

(Sorry for the back and forth here)

hokein updated this revision to Diff 296438.Oct 6 2020, 6:23 AM
hokein marked an inline comment as done.

address comments.

hokein added inline comments.Oct 6 2020, 6:30 AM
clang-tools-extra/clangd/refactor/Rename.cpp
124

yeah, I would leave it as-is for now. we could factor this out when there are more.

479

oh, you're right. And the documentation of the prepareRename is stale. Updated.

A slight concern of using a dummy name is that it may cause a name validation, but it should rarely happen if we choose some name like clangd_rename_dummy.

sammccall accepted this revision.Oct 6 2020, 6:31 AM
sammccall added inline comments.
clang-tools-extra/clangd/ClangdServer.cpp
416

oh, reserved name is clever :-)

Though it occurs to me - we could actually warn on rename to a reserved name!
(We can still do this and just ignore __clangd_*)

This revision is now accepted and ready to land.Oct 6 2020, 6:31 AM
hokein added inline comments.Oct 6 2020, 6:42 AM
clang-tools-extra/clangd/ClangdServer.cpp
416

giving a warning is nice, it seems too strict to forbidden users (library developers)) renaming a symbol to __a . The code is still compilable after all.

This revision was landed with ongoing or failed builds.Oct 6 2020, 6:48 AM
This revision was automatically updated to reflect the committed changes.