[PATCH] D35894: [clangd] Code hover for Clangd

Marc-Andre Laperle via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 29 15:37:49 PST 2017


malaperle added inline comments.


================
Comment at: clangd/ClangdUnit.cpp:1071
 
+Location getDeclarationLocation(ParsedAST &AST,
+                                const SourceRange &ValSourceRange) {
----------------
llvm::ErrorOr<Location>


================
Comment at: clangd/ClangdUnit.cpp:1075
+  const LangOptions &LangOpts = AST.getASTContext().getLangOpts();
+  SourceLocation LocStart = ValSourceRange.getBegin();
+  SourceLocation LocEnd = Lexer::getLocForEndOfToken(ValSourceRange.getEnd(), 0,
----------------
To fix the macro expansion crash:
```
SourceLocation LocStart = SourceMgr.getExpansionLoc(ValSourceRange.getBegin());
const FileEntry *F =
        SourceMgr.getFileEntryForID(SourceMgr.getFileID(LocStart));
```
and simple early return
```
if (!F)
  return llvm::errc::no_such_file_or_directory;
```


================
Comment at: clangd/ClangdUnit.cpp:1079
+  Position Begin;
+  Begin.line = SourceMgr.getSpellingLineNumber(LocStart) - 1;
+  Begin.character = SourceMgr.getSpellingColumnNumber(LocStart) - 1;
----------------
getExpansionLineNumber


================
Comment at: clangd/ClangdUnit.cpp:1080
+  Begin.line = SourceMgr.getSpellingLineNumber(LocStart) - 1;
+  Begin.character = SourceMgr.getSpellingColumnNumber(LocStart) - 1;
+  Position End;
----------------
getExpansionColumnNumber


================
Comment at: clangd/ClangdUnit.cpp:1082
+  Position End;
+  End.line = SourceMgr.getSpellingLineNumber(LocEnd) - 1;
+  End.character = SourceMgr.getSpellingColumnNumber(LocEnd) - 1;
----------------
getExpansionLineNumber


================
Comment at: clangd/ClangdUnit.cpp:1083
+  End.line = SourceMgr.getSpellingLineNumber(LocEnd) - 1;
+  End.character = SourceMgr.getSpellingColumnNumber(LocEnd) - 1;
+  Range R = {Begin, End};
----------------
getExpansionColumnNumber


================
Comment at: clangd/ClangdUnit.cpp:1087
+
+  const FileEntry *F =
+      SourceMgr.getFileEntryForID(SourceMgr.getFileID(LocStart));
----------------
You can do this earlier and simpler, see comment above.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D35894





More information about the cfe-commits mailing list