summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/XRefs.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [clangd] Upgrade logging facilities with levels and formatv.Sam McCall2018-07-111-2/+2
| | | | | | | | | | | | | | | | | | | | | | Summary: log() is split into four functions: - elog()/log()/vlog() have different severity levels, allowing filtering - dlog() is a lazy macro which uses LLVM_DEBUG - it logs to the logger, but conditionally based on -debug-only flag and is omitted in release builds All logging functions use formatv-style format strings now, e.g: log("Could not resolve URI {0}: {1}", URI, Result.takeError()); Existing log sites have been split between elog/log/vlog by best guess. This includes a workaround for passing Error to formatv that can be simplified when D49170 or similar lands. Subscribers: ilya-biryukov, javed.absar, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D49008 llvm-svn: 336785
* [clangd] Implementation of textDocument/documentSymbolMarc-Andre Laperle2018-07-051-14/+0
| | | | | | | | | | | | | | | | | Summary: An AST-based approach is used to retrieve the document symbols rather than an in-memory index query. The index is not an ideal fit to achieve this because of the file-centric query being done here whereas the index is suited for project-wide queries. Document symbols also includes more symbols and need to keep the order as seen in the file. Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Subscribers: tomgr, ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47846 llvm-svn: 336386
* [clangd] Incorporate transitive #includes into code complete proximity scoring.Sam McCall2018-07-031-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | Summary: We now compute a distance from the main file to the symbol header, which is a weighted count of: - some number of #include traversals from source file --> included file - some number of FS traversals from file --> parent directory - some number of FS traversals from parent directory --> child file/dir This calculation is performed in the appropriate URI scheme. This means we'll get some proximity boost from header files in main-file contexts, even when these are in different directory trees. This extended file proximity model is not yet incorporated in the index interface/implementation. Reviewers: ioeric Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D48441 llvm-svn: 336177
* [clangd] Implement hover for "auto" and "decltype"Marc-Andre Laperle2018-07-021-0/+142
| | | | | | | | | | | | | | | | | | | Summary: This allows hovering on keywords that refer to deduced types. This should cover most useful cases. Not covered: - auto template parameters: Since this can be instantiated with many types, it would not be practical to show the types. - Structured binding: This could be done later to show multiple deduced types in the hover. - auto:: (part of concepts): Outside the scope of this patch. Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D48159 llvm-svn: 336119
* [clangd] Hover should return null when not hovering over anything.Sam McCall2018-06-041-2/+2
| | | | | | | | | | | | Summary: Also made JSON serialize Optional<T> to simplify this. Reviewers: ioeric Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47701 llvm-svn: 333881
* [clangd] Remove accessors for top-level decls from preambleIlya Biryukov2018-05-281-2/+2
| | | | | | | | | | | | | | | | | | | | | | Summary: They cause lots of deserialization and are not actually used. The ParsedAST accessor that previously returned those was renamed from getTopLevelDecls to getLocalTopLevelDecls in order to avoid confusion. This change should considerably improve the speed of findDefinition and other features that try to find AST nodes, corresponding to the locations in the source code. Reviewers: ioeric, sammccall Reviewed By: sammccall Subscribers: klimek, mehdi_amini, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D47331 llvm-svn: 333371
* [clangd] Add helper for collecting #include directives in file.Eric Liu2018-05-141-5/+3
| | | | | | | | | | | | | | Summary: Separate unit tests for the new function will be added in followup patch which will further refactor Headers.h Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits Differential Revision: https://reviews.llvm.org/D46675 llvm-svn: 332237
* [clangd] Using index for GoToDefinition.Haojian Wu2018-04-301-60/+172
| | | | | | | | | | | | | | | | | | | Summary: This patch adds index support for GoToDefinition -- when we don't get the definition from local AST, we query our index (Static&Dynamic) index to get it. Since we currently collect top-level symbol in the index, it doesn't support all cases (e.g. class members), we will extend the index to include more symbols in the future. Reviewers: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits Differential Revision: https://reviews.llvm.org/D45717 llvm-svn: 331189
* [clangd] Fix unicode handling, using UTF-16 where LSP requires it.Sam McCall2018-04-271-15/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [index] Fix methods that take a shared_ptr to just take a reference.Benjamin Kramer2018-04-231-16/+16
| | | | | | | There is no ownership here, passing a shared_ptr just adds confusion. No functionality change intended. llvm-svn: 330595
* [clangd] Adapt index interfaces to D45014, and fix the old bugs.Sam McCall2018-04-091-29/+12
| | | | | | | | | | | | | Summary: Fix bugs: - don't count occurrences of decls where we don't spell the name - findDefinitions at MACRO(^X) goes to the definition of MACRO Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits Differential Revision: https://reviews.llvm.org/D45356 llvm-svn: 329571
* [clangd] Use the macro name range as the definition range.Haojian Wu2018-03-131-3/+2
| | | | | | | | | | | | | | Summary: This also aligns with the behavior of declarations. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D44423 llvm-svn: 327401
* [clangd] Fix irrelevant declaratations in goto definition (on macros).Haojian Wu2018-03-131-0/+10
| | | | | | | | | | | | | | | Summary: DeclrationAndMacrosFinder will find some declarations (not macro!) that are referened inside the macro somehow, isSearchedLocation() is not sufficient, we don't know whether the searched source location is macro or not. Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D44293 llvm-svn: 327387
* [clangd] Use identifier range as the definition range.Haojian Wu2018-03-091-4/+6
| | | | | | | | | | | | Summary: This also matches the range in symbol index. Reviewers: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D44247 llvm-svn: 327129
* [clangd] Early return for #include goto definition.Haojian Wu2018-03-081-10/+12
| | | | | | | | | | | | Summary: This would save cost of walking over the AST, NFC. Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, cfe-commits, ioeric Differential Revision: https://reviews.llvm.org/D44251 llvm-svn: 327023
* [clangd] #include statements support for Open definitionMarc-Andre Laperle2018-02-211-13/+14
| | | | | | | | | | | | | | Summary: ctrl-clicking on #include statements now opens the file being pointed by that statement. Reviewers: malaperle, krasimir, bkramer, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: jkorous-apple, ioeric, mgrang, klimek, ilya-biryukov, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D38639 llvm-svn: 325662
* [clangd] Fix formatting in XRefs.cppSimon Marchi2018-02-201-2/+2
| | | | | | This is also to test my commit access. llvm-svn: 325596
* [clangd] Fix use-after-free in SymbolYAML: strings are owned by yaml::Input!Sam McCall2018-02-191-2/+1
| | | | | | | | | | | | | | | | | | Summary: There are a few implementation options here - alternatives are either both awkward and inefficient, or really inefficient. This is at least potentially a hot path when used as a reducer for common symbols. (Also fix an unused-var that sneaked in) Reviewers: ioeric Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43381 llvm-svn: 325476
* [clangd] Rename some protocol field to lower caseMarc-Andre Laperle2018-02-161-6/+6
| | | | | | | | | | | | | Summary: Also fixes a GCC compilation error. Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D43411 llvm-svn: 325409
* [clangd] Implement textDocument/hoverMarc-Andre Laperle2018-02-161-8/+154
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Implemention of textDocument/hover as described in LSP definition. This patch adds a basic Hover implementation. When hovering a variable, function, method or namespace, clangd will return a text containing the declaration's scope, as well as the declaration of the hovered entity. For example, for a variable: Declared in class Foo::Bar int hello = 2 For macros, the macro definition is returned. This patch doesn't include: - markdown support (the client I use doesn't support it yet) - range support (optional in the Hover response) - comments associated to variables/functions/classes They are kept as future work to keep this patch simpler. I added tests in XRefsTests.cpp. hover.test contains one simple smoketest to make sure the feature works from a black box perspective. Reviewers: malaperle, krasimir, bkramer, ilya-biryukov Subscribers: sammccall, mgrang, klimek, rwols, ilya-biryukov, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D35894 Signed-off-by: Simon Marchi <simon.marchi@ericsson.com> Signed-off-by: William Enright <william.enright@polymtl.ca> llvm-svn: 325395
* [clangd] Assert path is absolute when assigning to URIForFile.Ilya Biryukov2018-02-161-1/+1
| | | | | | | | | | | | | | | | Summary: The assertion will point directly to misbehaving code, so that debugging related problems (like the one fixed by r325029) is easier. Reviewers: hokein, ioeric, sammccall Reviewed By: sammccall Subscribers: klimek, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43246 llvm-svn: 325337
* [clangd] Fixed findDefinitions to always return absolute paths.Ilya Biryukov2018-02-131-2/+10
| | | | | | | | Relative paths could be returned in some cases, e.g. when relative path is used in compilation arguments. This led to crash when trying to convert the path to URI. llvm-svn: 325029
* [clangd] Pass Context implicitly using TLS.Sam McCall2018-01-311-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Instead of passing Context explicitly around, we now have a thread-local Context object `Context::current()` which is an implicit argument to every function. Most manipulation of this should use the WithContextValue helper, which augments the current Context to add a single KV pair, and restores the old context on destruction. Advantages are: - less boilerplate in functions that just propagate contexts - reading most code doesn't require understanding context at all, and using context as values in fewer places still - fewer options to pass the "wrong" context when it changes within a scope (e.g. when using Span) - contexts pass through interfaces we can't modify, such as VFS - propagating contexts across threads was slightly tricky (e.g. copy vs move, no move-init in lambdas), and is now encapsulated in the threadpool Disadvantages are all the usual TLS stuff - hidden magic, and potential for higher memory usage on threads that don't use the context. (In practice, it's just one pointer) Reviewers: ilya-biryukov Subscribers: klimek, jkorous-apple, ioeric, cfe-commits Differential Revision: https://reviews.llvm.org/D42517 llvm-svn: 323872
* [clangd] Use new URI with scheme support in place of the existing LSP URIEric Liu2018-01-291-1/+3
| | | | | | | | | | | | | | | | | | Summary: o Replace the existing clangd::URI with a wrapper of FileURI which also carries a resolved file path. o s/FileURI/URI/ o Get rid of the URI hack in vscode extension. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D42419 llvm-svn: 323660
* [clangd] Don't navigate to forward class declaration when go to definition.Haojian Wu2018-01-121-2/+26
| | | | | | | | | | | | | | | | Summary: For some cases, GoToDefinition will navigate to the forward class declaration, we should always navigate to the class definition. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, ilya-biryukov, cfe-commits Differential Revision: https://reviews.llvm.org/D41661 llvm-svn: 322370
* [clangd] Split findDefs/highlights into XRefs, from ClangdUnit. NFCSam McCall2017-12-191-0/+270
Going to add unit tests in the next patch. (Haha!) But seriously there's some work to do first - need to extract the markers-in-source-code parser from CodeComplete test and make it more flexible, to allow annotated ranges etc. llvm-svn: 321087
OpenPOWER on IntegriCloud