This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Add --check-range to restrict --check to specific lines
ClosedPublic

Authored by adamcz on Mar 19 2021, 10:59 AM.

Details

Summary

This will allow us to add code completion, which is too expensive at
every token, to --check too.

Diff Detail

Event Timeline

adamcz created this revision.Mar 19 2021, 10:59 AM
adamcz requested review of this revision.Mar 19 2021, 10:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 19 2021, 10:59 AM

This has been annoying me for a while ;-)

sammccall accepted this revision.Mar 23 2021, 9:38 AM

Thanks! Just some random nits/ideas.

clang-tools-extra/clangd/tool/Check.cpp
206

you already have the line number as Pos.start.line

clang-tools-extra/clangd/tool/ClangdMain.cpp
64

You could also pass in a function_ref<bool(const Position&)> which feels a bit more self-documenting

352

nit: check-lines, which documents the units?

354

seems likely the common case will be a single line, and --check-range=254-254 is a little awkward.
Supporting --check-range=254 seems worthwhile?

921

(I'd omit this if the flag is just ignored and harmless. There should be no danger of expecting it to check something if you didn't provide a filename...)

This revision is now accepted and ready to land.Mar 23 2021, 9:38 AM
adamcz updated this revision to Diff 335536.Apr 6 2021, 9:05 AM
adamcz marked 4 inline comments as done.

addressed review comments + rebase to latest version

clang-tools-extra/clangd/tool/ClangdMain.cpp
354

Good idea. Done

921

I'd rather keep it. If you specify --check-lines without --check you're doing something wrong and going into LSP mode is unlikely to be useful. If it's part of the script, you might wait a minute or two until you realize it's not actually working.

sammccall accepted this revision.Apr 6 2021, 9:11 AM

Still LG

clang-tools-extra/clangd/tool/ClangdMain.cpp
898–917

nit: consider pulling out a helper function to parse this that returns std:;function

adamcz added inline comments.Apr 6 2021, 9:34 AM
clang-tools-extra/clangd/tool/ClangdMain.cpp
898–917

It gets a bit ugly, since we need a way to report an error. So it's either returning some ErrorOr<std::function> or elog() + exit(1) from a getShouldCheckLines() function.

If you prefer, I can do that, but I feel like this will hurt readability because of the error handling.