Commit Graph

257 Commits

Author SHA1 Message Date
Simon Pilgrim dc15bedfb9 Fix MSVC "not all control paths return a value" warning 2022-04-07 14:01:15 +01:00
Jun Zhang f2796a5d44
Link aganist clangSema to fix broken build.
Signed-off-by: Jun Zhang <jun@junz.org>
2022-04-07 10:50:50 +08:00
Sam McCall afa94306a8 [clangd] Add code action to generate a constructor for a C++ class
Differential Revision: https://reviews.llvm.org/D116514
2022-04-06 16:23:50 +02:00
Sam McCall 68eac9a6e7 [clangd] Code action to declare missing move/copy constructor/assignment
Fixes https://github.com/clangd/clangd/issues/973

Differential Revision: https://reviews.llvm.org/D116490
2022-04-06 16:14:42 +02:00
Fabio Rossini Sluzala a0e4ba4b46 [clangd] Add support to extract method for ExtractFunction Tweak
I miss more automatically refactoring functions when working with already running code, so I am making some small addition that I hope help more people.

This works by checking if the function is a method (CXXMethodDecl), then collecting information about the function that the code is being extracted, looking for the declaration if it is out-of-line, creating the declaration if it is necessary and putting the extracted function as a class-method.

This is my first code review request, sorry if I did something wrong.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D122698
2022-04-05 19:49:17 +02:00
Sam McCall 6f3f1e9868 [clangd] Remove trivial uses of FileEntry::getName
It's deprecated; migrate to FileEntryRef::getName where it doesn't matter.
Also change one subtle case of implicit FileEntry::getName to be explicit.

After this patch, all the remaining FileEntry::getName calls are subtle
cases where we may be relying on exactly which filename variant is returned
(for indexing, IWYU directive handling, etc).
2022-04-04 20:59:51 +02:00
Sam McCall 46dbd19afb [clangd] Fix nullptr crash in AddUsing tweak on catch(...)
Fixes https://github.com/clangd/clangd/issues/1072
2022-03-21 18:56:45 +01:00
David Goldman 1af5fbd5c6 [clangd] Code action for creating an ObjC initializer
The code action creates an initializer for the selected
ivars/properties, defaulting to all if only the interface/implementation
container is selected.

We add it based on the position of the first non initializer that we
see, and default to adding it where the @end token is.

We also use the ObjC parameter form of (nullable id) instead of
(id _Nullable) if the property has the nullable attribute.

Differential Revision: https://reviews.llvm.org/D116385
2022-03-17 11:31:14 -04:00
Sam McCall 4d006520b8 [clangd] Clean up unused includes. NFCI
Add includes where needed to fix build.
Haven't systematically added used headers, so there is still accidental
dependency on transitive includes.
2022-02-26 12:00:16 +01:00
Sam McCall b9b6938183 [clangd] Treat 'auto' params as deduced if there's a single instantiation.
This makes hover/go-to-definition/expand-auto etc work for auto params in many
common cases.
This includes when a generic lambda is passed to a function accepting
std::function. (The tests don't use this case, it requires a lot of setup).

Note that this doesn't affect the AST of the function body itself, cause its
nodes not to be dependent, improve code completion etc.
(These sort of improvements seem possible, in a similar "if there's a single
instantiation, traverse it instead of the primary template" way).

Fixes https://github.com/clangd/clangd/issues/493
Fixes https://github.com/clangd/clangd/issues/1015

Differential Revision: https://reviews.llvm.org/D119537
2022-02-21 13:24:11 +01:00
Simon Pilgrim 535e7b09c1 [clangd] lookupSiblingsWithinContext - remove unnecessary nullptr check
The DC pointer is always dereferenced after the loop
2022-02-18 11:12:53 +00:00
Christian Kühnel 2f8da95e07 [clangd][nfc] cleanup of remaining clang-tidy findings
There were some left-overs (or new things) from the previous patches.

This will get us down to 0 open findings except:
clang-tidy is complaining in some files about
`warning: #includes are not sorted properly [llvm-include-order]`
however, clang-format does revert these changes.
It looks like clang-tidy and clang-format disagree there.

Not sure how we can fix that...

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D118698
2022-02-03 12:05:25 +00:00
Christian Kühnel c0e3c893aa [NFC][clangd] cleaning up llvm-qualified-auto
This is a cleanup of all llvm-qualified-auto findings.
This patch was created by automatically applying the fixes from
clang-tidy.

Differential Revision: https://reviews.llvm.org/D113898
2022-01-25 13:26:33 +00:00
Kirill Bobyrev 2d9198cec9
[clangd] Remove redundant check for renamed symbol origin
This is a follow-up on D116643. `isInSystemHeader` check already detects
symbols coming from the Standard Library, so searching for the qualified name
in StdSymbolMap.inc is no longer necessary.

The tests filtering out purely based on the symbol qualified names are removed.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D117491
2022-01-18 09:43:53 +01:00
Haojian Wu 192f8d9700 [clangd] Don't rename on symbols from system headers.
Fixes https://github.com/clangd/clangd/issues/963.

Differential Revision: https://reviews.llvm.org/D116643
2022-01-17 15:08:53 +01:00
Haojian Wu ab3f100bec Reland (2) "[AST] Add RParen loc for decltype AutoTypeloc.""
The patch was reverted because it caused a crash during PCH build -- we
missed to update the RParenLoc in TreeTransform<Derived>::TransformAutoType.

This relands 55d96ac and 37ec65e with a test and fix.
2022-01-17 11:33:11 +01:00
Florian Hahn eadb4cfeef
Revert (2) "[AST] Add RParen loc for decltype AutoTypeloc."
This reverts commit 41fbdfa4d5.

The commit breaks stage 2 builds with debug info, e.g.
https://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/5088/console

Clang crashes with the following assertion when building
llvm-project/llvm/lib/Support/Timer.cpp

/usr/local/bin/sccache /Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/host-compiler/bin/clang++  -DGTEST_HAS_RTTI=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Support -I/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/lib/Support -Iinclude -I/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/include -fno-stack-protector -fno-common -Wno-profile-instr-unprofiled -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -fmodules -fmodules-cache-path=/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/clang-build/Build/module.cache -fcxx-modules -Xclang -fmodules-local-submodule-visibility -gmodules -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -flto=thin  -O2 -g -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk   -std=c++14  -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o -MF lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o.d -o lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o -c /Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/lib/Support/Timer.cpp
Assertion failed: (((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow"), function getLocWithOffset, file /Users/buildslave/jenkins/workspace/clang-stage1-RA/llvm-project/clang/include/clang/Basic/SourceLocation.h, line 135.
2022-01-12 10:09:37 +00:00
Haojian Wu 41fbdfa4d5 Reland "[AST] Add RParen loc for decltype AutoTypeloc."
Reland 55d96ac and 37ec65e with a clang-tidy fix.
2022-01-11 12:06:18 +01:00
Nico Weber cf90b3cf7e Revert "[clangd] Enable expand-auto for decltype(auto)."
This reverts commit 37ec65e1d7.

Its prerequisite 55d96ac3dc wsa
reverted in c2293bc17d. c2293bc's
patch description claimed that it reverted 37ec65 as well,
but it apparently didn't.

See https://reviews.llvm.org/D116921#3231802
2022-01-10 12:01:42 -05:00
Haojian Wu 37ec65e1d7 [clangd] Enable expand-auto for decltype(auto).
Based on https://reviews.llvm.org/D116919.

Fixes https://github.com/clangd/clangd/issues/121

Differential Revision: https://reviews.llvm.org/D116921
2022-01-10 13:46:56 +01:00
Kazu Hirata 8afcfbfb8f Use true/false instead of 1/0 (NFC)
Identified by modernize-use-bool-literals.
2022-01-09 12:21:06 -08:00
Sam McCall fe68088d44 [clangd] Helper for determining member insertion point.
To be used in D116490 and D116385, and an upcoming patch to generate C++
constructors.

Differential Revision: https://reviews.llvm.org/D116502
2022-01-03 17:59:45 +01:00
Aleksandr Platonov 555eacf75f [clangd] Fix undefined behavior when generating error message at rename with an invalid name
`Message()` lambda uses `Reason.Details` as an input parameter for `llvm::formatv()`, but `Reason` in `Message()` is a local object.
Return value of `llvm::formatv()` contains references to its input arguments, thus `Message()` returns an object which contains a reference to `Details` field of the local object `Reason`.
This patch fixes this behavior by passing `Reason` as a reference to `Message()` to ensure that return value of `Message()` contains references to alive object and also prevents copying of `InvalidName` structure at passing it to `makeError()`.

Provided test passes on Linux+GCC with or without this patch, but fails on Windows+VisualStudio without this patch.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D115959
2021-12-19 22:28:26 +03:00
Christian Kühnel 5bd643d31d [clangd] cleanup of header guard names
Renaming header guards to match the LLVM convention.
This patch was created by automatically applying the fixes from
clang-tidy.

I've removed the [NFC]  tag from the title, as we're adding header guards in some files and thus might trigger behavior changes.

Differential Revision: https://reviews.llvm.org/D113896
2021-12-02 15:58:35 +00:00
Christian Kühnel ec4a2c9565 [NFC][clangd] cleanup llvm-else-after-return findings
Cleanup of clang-tidy findings: removing "else" after a return statement
to improve readability of the code.

This patch was created by applying the clang-tidy fixes automatically.

Differential Revision: https://reviews.llvm.org/D113892
2021-11-17 14:37:03 +00:00
Kazu Hirata 972d4133e9 Use {DenseSet,SmallPtrSet}::contains (NFC) 2021-10-29 20:26:07 -07:00
Kadir Cetinkaya fbf1745722
[clangd] Escape error message in AddUsing
Fixes https://github.com/clangd/clangd/issues/900
2021-10-28 14:52:12 +02:00
Adam Czachorowski 2174524116 [clangd] AddUsing: Fix support for template specializations.
Before this change, we would add "using std::vector<int>" instead of
just "using std::vector;", which would not even compile.

Fixes https://github.com/clangd/clangd/issues/904

Differential Revision: https://reviews.llvm.org/D112530
2021-10-26 17:32:33 +02:00
David Goldman a90d57b6cc [clangd] Improve PopulateSwitch tweak
- Support enums in C and ObjC as their
  AST representations differ slightly.

- Add support for typedef'ed enums.

Differential Revision: https://reviews.llvm.org/D110954
2021-10-04 10:15:37 -04:00
Corentin Jabot 601102d282 Cleanup identifier parsing; NFC
Rename methods to clearly signal when they only deal with ASCII,
simplify the parsing of identifier, and use start/continue instead of
head/body for consistency with Unicode terminology.
2021-09-14 09:12:22 -04:00
Sam McCall c5c3cdb9c9 [clangd] Populate-switch triggers when the whole condition is selected.
This allows vscode to find it as a diagnostic quickfix for -Wswitch.

While here, group the code into chunks and add a couple more comments.
2021-08-08 21:06:08 +02:00
Kadir Cetinkaya 614b46e4dc
[clangd] Add a flag to disable formatting of tweak edits
Some tweaks might edit file types not supported by clang-format. This
patch gives them a way to signal that they do not require formatting.

Differential Revision: https://reviews.llvm.org/D105039
2021-06-28 20:52:47 +02:00
Sam McCall 6aca6032c5 [AST] Include the TranslationUnitDecl when traversing with TraversalScope
Given `int foo, bar;`, TraverseAST reveals this tree:
  TranslationUnitDecl
   - foo
   - bar

Before this patch, with the TraversalScope set to {foo}, TraverseAST yields:
  foo

After this patch it yields:
  TranslationUnitDecl
  - foo

Also, TraverseDecl(TranslationUnitDecl) now respects the traversal scope.

---

The main effect of this today is that clang-tidy checks that match the
translationUnitDecl(), either in order to traverse it or check
parentage, should work.

Differential Revision: https://reviews.llvm.org/D104071
2021-06-11 14:29:45 +02:00
Haojian Wu d30c202d27 [clangd] don't rename if the triggering loc is not actually being renamed.
See context: https://github.com/clangd/clangd/issues/765

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D101816
2021-06-11 13:51:50 +02:00
Nathan James 6b4e8f82a3
[clangd] Use dirty filesystem when performing cross file tweaks
Cross file tweaks can now use the dirty buffer contents easily when performing cross file effects.
This can be noted on the DefineOutline tweak, now working when the target file is unsaved

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93978
2021-04-20 17:13:44 +01:00
Kadir Cetinkaya b5b2c81055
[clangd] Propagate data in diagnostics
Differential Revision: https://reviews.llvm.org/D98505
2021-04-13 17:45:09 +02:00
Kadir Cetinkaya bb6d96ced8
[clangd] Enable modules to contribute tweaks.
First patch to enable diagnostic fix generation through modules. The
workflow will look like:
- ASTWorker letting modules know about diagnostics while building AST,
modules can read clang::Diagnostic and mutate clangd::Diagnostic through
that hook.
- Modules can implement and expose tweaks to fix diagnostics or act as
general refactorings.
- Tweak::Selection will contain information about the diagnostic
associated with the codeAction request to enable modules to fail their
diagnostic fixing tweakson prepare if need be.

Differential Revision: https://reviews.llvm.org/D98498
2021-04-13 17:45:08 +02:00
Kadir Cetinkaya f71404c37c
[clangd] Replace usages of dummy with more descriptive words
Dummy is a word with inappropriate associations. This patch updates the
references to it in clangd code base with more precise ones.

The only user-visible change is the default variable name used when extracting a
variable. It will be named as `placeholder` from now on.

Differential Revision: https://reviews.llvm.org/D99065
2021-03-22 12:49:24 +01:00
Sam McCall 43d0b1c9c1 [clangd] Reject renames to non-identifier characters
Differential Revision: https://reviews.llvm.org/D98424
2021-03-16 12:18:29 +01:00
Kadir Cetinkaya b1a5df174e
[clangd] Drop explicit specifier on define out-of-line
Explicit specifier can only be mentioned on the in-line declaration of a
constructor, so don't carry it over to the definition.

Differential Revision: https://reviews.llvm.org/D98164
2021-03-11 13:27:24 +01:00
Nathan James 7044f1d875
[clangd] Use Dirty Filesystem for cross file rename.
Refactor cross file rename to use a Filesystem instead of a function for getting buffer contents of open files.

Depends on D94554

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95043
2021-03-10 13:41:29 +00:00
Nathan Ridge 9510b09402 [clangd] Factor out the heuristic resolver code into its own class
The patch also does some cleanup on the interface of the entry
points from TargetFinder into the heuristic resolution code.

Since the heuristic resolver is created in a place where the
ASTContext is available, it can store the ASTContext and the
NameFactory hack can be removed.

Differential revision: https://reviews.llvm.org/D92290
2021-02-16 04:10:52 -05:00
Haojian Wu ee4dd0f876 [clangd] Remove the cross-file-rename option.
and simplify the code.

Differential Revision: https://reviews.llvm.org/D96578
2021-02-12 15:38:55 +01:00
Haojian Wu 573348ab9b [clangd] Retire the cross-file-rename command-line flag.
This patch only focuses on the flag. Removing actual single-file mode
(and the flag in RenameOption) will come in a follow-up.

Differential Revision: https://reviews.llvm.org/D96495
2021-02-11 20:28:50 +01:00
Sam McCall dd8fb21227 [clangd] Implement semanticTokens modifiers
- Infrastructure to support modifiers (protocol etc)
- standard modifiers:
  - declaration (but no definition, yet)
  - deprecated
  - readonly (based on a fairly fuzzy const checking)
  - static (for class members and locals, but *not* file-scope things!)
  - abstract (for C++ classes, and pure-virtual methods)
- nonstandard modifier:
  - deduced (on "auto" whose Kind is Class etc)
    Happy to drop this if it's controversial at all.
- While here, update sample tweak to use our internal names, in
  anticipation of theia TM scopes going away.

This addresses some of the goals of D77702, but leaves some things undone.
Mostly because I think these will want some discussion.
 - no split between dependent type/name.
   (We may want to model this as a modifier, type+dependent vs ???+dependent)
 - no split between primitive/typedef.
   (Is introducing a nonstandard kind is worth this distinction?)
 - no nonstandard local attribute
   This probably makes sense, I'm wondering if we want others and how
   they fit together.

There's one minor regression in explicit template specialization declarations
due to a latent bug in findExplicitReferences, but fixing it after seems OK.

Differential Revision: https://reviews.llvm.org/D77811
2021-02-09 16:31:22 +01:00
Kirill Bobyrev b60428c7ea [clangd] Fix false positive in local rename collision detetction
Fixes https://github.com/clangd/clangd/issues/685

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D96247
2021-02-09 11:51:18 +01:00
Kirill Bobyrev e8a2b7c915 [clangd] Improve name conflict detection
Follow-up on D95925: adds better detection for function arguments and also
checks for conflicts in muli-variable init statements in ForStmt.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D96009
2021-02-04 21:37:41 +01:00
Kirill Bobyrev 5eec9a380a
[clangd] Detect rename conflicits within enclosing scope
This patch allows detecting conflicts with variables defined in the current
CompoundStmt or If/While/For variable init statements.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D95925
2021-02-04 09:45:42 +01:00
Sam McCall b63cd4db91 [clangd] Rename: merge index/AST refs path-insensitively where needed
If you have c:\foo open, and C:\foo indexed (case difference) then these
need to be considered the same file. Otherwise we emit edits to both,
and editors do... something that isn't pretty.

Maybe more centralized normalization is called for, but it's not trivial
to do this while also being case-preserving. see
https://github.com/clangd/clangd/issues/108

Fixes https://github.com/clangd/clangd/issues/665

Differential Revision: https://reviews.llvm.org/D95759
2021-02-01 15:15:21 +01:00
Adam Czachorowski aeaeb9e6bd [clangd] Make ExpandAutoType not available on template params.
We cannot expand auto when used inside a template param (C++17 feature),
so do not offer it there.

Differential Revision: https://reviews.llvm.org/D94719
2021-01-15 14:19:05 +01:00