2018-08-15 00:03:32 +08:00
|
|
|
//===--- XRefs.h -------------------------------------------------*- C++-*-===//
|
2017-12-20 01:06:07 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-12-20 01:06:07 +08:00
|
|
|
//
|
2018-08-15 00:03:32 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2017-12-20 01:06:07 +08:00
|
|
|
//
|
|
|
|
// Features that traverse references between symbols.
|
|
|
|
//
|
2018-08-15 00:03:32 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-12-20 01:06:07 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
|
|
|
|
|
|
|
|
#include "ClangdUnit.h"
|
|
|
|
#include "Protocol.h"
|
2018-04-30 23:24:17 +08:00
|
|
|
#include "index/Index.h"
|
2018-06-04 18:37:16 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2017-12-20 01:06:07 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
|
[clangd] Implement textDocument/declaration from LSP 3.14
Summary:
LSP now reflects the declaration/definition distinction.
Language server changes:
- textDocument/definition now returns a definition if one is found, otherwise
the declaration. It no longer returns declaration + definition if they are
distinct.
- textDocument/declaration returns the best declaration we can find.
- For macros, the active macro definition is returned for both methods.
- For include directive, the top of the target file is returned for both.
There doesn't appear to be a discovery mechanism (we can't return everything to
clients that only know about definition), so this changes existing behavior.
In practice, it should greatly reduce the fraction of the time we need to show
the user a menu of options.
C++ API changes:
- findDefinitions is replaced by locateSymbolAt, which returns a
vector<LocatedSymbol> - one for each symbol under the cursor.
- this contains the preferred declaration, the definition (if found), and
the symbol name
This API enables some potentially-neat extensions, like swapping between decl
and def, and exposing the symbol name to the UI in the case of multiple symbols.
Reviewers: hokein
Subscribers: ilya-biryukov, javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D57388
llvm-svn: 352864
2019-02-01 19:26:13 +08:00
|
|
|
// Describes where a symbol is declared and defined (as far as clangd knows).
|
|
|
|
// There are three cases:
|
|
|
|
// - a declaration only, no definition is known (e.g. only header seen)
|
|
|
|
// - a declaration and a distinct definition (e.g. function declared in header)
|
|
|
|
// - a declaration and an equal definition (e.g. inline function, or class)
|
|
|
|
// For some types of symbol, e.g. macros, definition == declaration always.
|
|
|
|
struct LocatedSymbol {
|
|
|
|
// The (unqualified) name of the symbol.
|
|
|
|
std::string Name;
|
|
|
|
// The canonical or best declaration: where most users find its interface.
|
|
|
|
Location PreferredDeclaration;
|
|
|
|
// Where the symbol is defined, if known. May equal PreferredDeclaration.
|
|
|
|
llvm::Optional<Location> Definition;
|
|
|
|
};
|
|
|
|
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const LocatedSymbol &);
|
2017-12-20 01:06:07 +08:00
|
|
|
/// Get definition of symbol at a specified \p Pos.
|
[clangd] Implement textDocument/declaration from LSP 3.14
Summary:
LSP now reflects the declaration/definition distinction.
Language server changes:
- textDocument/definition now returns a definition if one is found, otherwise
the declaration. It no longer returns declaration + definition if they are
distinct.
- textDocument/declaration returns the best declaration we can find.
- For macros, the active macro definition is returned for both methods.
- For include directive, the top of the target file is returned for both.
There doesn't appear to be a discovery mechanism (we can't return everything to
clients that only know about definition), so this changes existing behavior.
In practice, it should greatly reduce the fraction of the time we need to show
the user a menu of options.
C++ API changes:
- findDefinitions is replaced by locateSymbolAt, which returns a
vector<LocatedSymbol> - one for each symbol under the cursor.
- this contains the preferred declaration, the definition (if found), and
the symbol name
This API enables some potentially-neat extensions, like swapping between decl
and def, and exposing the symbol name to the UI in the case of multiple symbols.
Reviewers: hokein
Subscribers: ilya-biryukov, javed.absar, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D57388
llvm-svn: 352864
2019-02-01 19:26:13 +08:00
|
|
|
/// Multiple locations may be returned, corresponding to distinct symbols.
|
|
|
|
std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
|
|
|
|
const SymbolIndex *Index = nullptr);
|
2017-12-20 01:06:07 +08:00
|
|
|
|
|
|
|
/// Returns highlights for all usages of a symbol at \p Pos.
|
[clangd] Pass Context implicitly using TLS.
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
2018-01-31 21:40:48 +08:00
|
|
|
std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST,
|
|
|
|
Position Pos);
|
2017-12-20 01:06:07 +08:00
|
|
|
|
[clangd] Implement textDocument/hover
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
2018-02-17 05:38:15 +08:00
|
|
|
/// Get the hover information when hovering at \p Pos.
|
2018-06-04 18:37:16 +08:00
|
|
|
llvm::Optional<Hover> getHover(ParsedAST &AST, Position Pos);
|
[clangd] Implement textDocument/hover
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
2018-02-17 05:38:15 +08:00
|
|
|
|
2018-09-05 18:33:36 +08:00
|
|
|
/// Returns reference locations of the symbol at a specified \p Pos.
|
2019-01-15 02:11:09 +08:00
|
|
|
/// \p Limit limits the number of results returned (0 means no limit).
|
2018-09-05 18:33:36 +08:00
|
|
|
std::vector<Location> findReferences(ParsedAST &AST, Position Pos,
|
2019-01-15 02:11:09 +08:00
|
|
|
uint32_t Limit,
|
2018-09-05 18:33:36 +08:00
|
|
|
const SymbolIndex *Index = nullptr);
|
|
|
|
|
2018-11-28 00:40:46 +08:00
|
|
|
/// Get info about symbols at \p Pos.
|
|
|
|
std::vector<SymbolDetails> getSymbolInfo(ParsedAST &AST, Position Pos);
|
|
|
|
|
2017-12-20 01:06:07 +08:00
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
2018-08-15 00:03:32 +08:00
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_XREFS_H
|