Skip to content

Commit 079ef78

Browse files
committed
Revert "[clangd] Implement "textDocument/documentLink" protocol support"
This reverts commit d6417f5. The tests depend on builtin headers, which is not intentionally supported in clangd tests; these tests are broken in some build environments.
1 parent 4658da1 commit 079ef78

File tree

11 files changed

+0
-175
lines changed

11 files changed

+0
-175
lines changed

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,6 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
566566
{"declarationProvider", true},
567567
{"definitionProvider", true},
568568
{"documentHighlightProvider", true},
569-
{"documentLinkProvider",
570-
llvm::json::Object{
571-
{"resolveProvider", false},
572-
}},
573569
{"hoverProvider", true},
574570
{"renameProvider", std::move(RenameProvider)},
575571
{"selectionRangeProvider", true},
@@ -1204,25 +1200,6 @@ void ClangdLSPServer::onSelectionRange(
12041200
});
12051201
}
12061202

1207-
void ClangdLSPServer::onDocumentLink(
1208-
const DocumentLinkParams &Params,
1209-
Callback<std::vector<DocumentLink>> Reply) {
1210-
1211-
// TODO(forster): This currently resolves all targets eagerly. This is slow,
1212-
// because it blocks on the preamble/AST being built. We could respond to the
1213-
// request faster by using string matching or the lexer to find the includes
1214-
// and resolving the targets lazily.
1215-
Server->documentLinks(
1216-
Params.textDocument.uri.file(),
1217-
[Reply = std::move(Reply)](
1218-
llvm::Expected<std::vector<DocumentLink>> Links) mutable {
1219-
if (!Links) {
1220-
return Reply(Links.takeError());
1221-
}
1222-
return Reply(std::move(Links));
1223-
});
1224-
}
1225-
12261203
ClangdLSPServer::ClangdLSPServer(
12271204
class Transport &Transp, const FileSystemProvider &FSProvider,
12281205
const clangd::CodeCompleteOptions &CCOpts,
@@ -1266,7 +1243,6 @@ ClangdLSPServer::ClangdLSPServer(
12661243
MsgHandler->bind("textDocument/typeHierarchy", &ClangdLSPServer::onTypeHierarchy);
12671244
MsgHandler->bind("typeHierarchy/resolve", &ClangdLSPServer::onResolveTypeHierarchy);
12681245
MsgHandler->bind("textDocument/selectionRange", &ClangdLSPServer::onSelectionRange);
1269-
MsgHandler->bind("textDocument/documentLink", &ClangdLSPServer::onDocumentLink);
12701246
// clang-format on
12711247
}
12721248

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ class ClangdLSPServer : private DiagnosticsConsumer {
111111
Callback<std::vector<SymbolDetails>>);
112112
void onSelectionRange(const SelectionRangeParams &,
113113
Callback<std::vector<SelectionRange>>);
114-
void onDocumentLink(const DocumentLinkParams &,
115-
Callback<std::vector<DocumentLink>>);
116114

117115
std::vector<Fix> getFixes(StringRef File, const clangd::Diagnostic &D);
118116

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -611,17 +611,6 @@ void ClangdServer::semanticRanges(PathRef File, Position Pos,
611611
WorkScheduler.runWithAST("SemanticRanges", File, std::move(Action));
612612
}
613613

614-
void ClangdServer::documentLinks(PathRef File,
615-
Callback<std::vector<DocumentLink>> CB) {
616-
auto Action =
617-
[CB = std::move(CB)](llvm::Expected<InputsAndAST> InpAST) mutable {
618-
if (!InpAST)
619-
return CB(InpAST.takeError());
620-
CB(clangd::getDocumentLinks(InpAST->AST));
621-
};
622-
WorkScheduler.runWithAST("DocumentLinks", File, std::move(Action));
623-
}
624-
625614
std::vector<std::pair<Path, std::size_t>>
626615
ClangdServer::getUsedBytesPerFile() const {
627616
return WorkScheduler.getUsedBytesPerFile();

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,6 @@ class ClangdServer {
287287
void semanticRanges(PathRef File, Position Pos,
288288
Callback<std::vector<Range>> CB);
289289

290-
/// Get all document links in a file.
291-
void documentLinks(PathRef File, Callback<std::vector<DocumentLink>> CB);
292-
293290
/// Returns estimated memory usage for each of the currently open files.
294291
/// The order of results is unspecified.
295292
/// Overall memory usage of clangd may be significantly more than reported

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,18 +1087,5 @@ llvm::json::Value toJSON(const SelectionRange &Out) {
10871087
}
10881088
return llvm::json::Object{{"range", Out.range}};
10891089
}
1090-
1091-
bool fromJSON(const llvm::json::Value &Params, DocumentLinkParams &R) {
1092-
llvm::json::ObjectMapper O(Params);
1093-
return O && O.map("textDocument", R.textDocument);
1094-
}
1095-
1096-
llvm::json::Value toJSON(const DocumentLink &DocumentLink) {
1097-
return llvm::json::Object{
1098-
{"range", DocumentLink.range},
1099-
{"target", DocumentLink.target},
1100-
};
1101-
}
1102-
11031090
} // namespace clangd
11041091
} // namespace clang

clang-tools-extra/clangd/Protocol.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,39 +1250,6 @@ struct SelectionRange {
12501250
};
12511251
llvm::json::Value toJSON(const SelectionRange &);
12521252

1253-
/// Parameters for the document link request.
1254-
struct DocumentLinkParams {
1255-
/// The document to provide document links for.
1256-
TextDocumentIdentifier textDocument;
1257-
};
1258-
bool fromJSON(const llvm::json::Value &, DocumentLinkParams &);
1259-
1260-
/// A range in a text document that links to an internal or external resource,
1261-
/// like another text document or a web site.
1262-
struct DocumentLink {
1263-
/// The range this link applies to.
1264-
Range range;
1265-
1266-
/// The uri this link points to. If missing a resolve request is sent later.
1267-
URIForFile target;
1268-
1269-
// TODO(forster): The following optional fields defined by the language
1270-
// server protocol are unsupported:
1271-
//
1272-
// data?: any - A data entry field that is preserved on a document link
1273-
// between a DocumentLinkRequest and a
1274-
// DocumentLinkResolveRequest.
1275-
1276-
friend bool operator==(const DocumentLink &LHS, const DocumentLink &RHS) {
1277-
return LHS.range == RHS.range && LHS.target == RHS.target;
1278-
}
1279-
1280-
friend bool operator!=(const DocumentLink &LHS, const DocumentLink &RHS) {
1281-
return !(LHS == RHS);
1282-
}
1283-
};
1284-
llvm::json::Value toJSON(const DocumentLink &DocumentLink);
1285-
12861253
} // namespace clangd
12871254
} // namespace clang
12881255

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,6 @@ llvm::Optional<Location> makeLocation(ASTContext &AST, SourceLocation TokLoc,
166166

167167
} // namespace
168168

169-
std::vector<DocumentLink> getDocumentLinks(ParsedAST &AST) {
170-
const auto &SM = AST.getSourceManager();
171-
auto MainFilePath =
172-
getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM);
173-
if (!MainFilePath) {
174-
elog("Failed to get a path for the main file, so no links");
175-
return {};
176-
}
177-
178-
std::vector<DocumentLink> Result;
179-
for (auto &Inc : AST.getIncludeStructure().MainFileIncludes) {
180-
if (!Inc.Resolved.empty()) {
181-
Result.push_back(DocumentLink(
182-
{Inc.R, URIForFile::canonicalize(Inc.Resolved, *MainFilePath)}));
183-
}
184-
}
185-
186-
return Result;
187-
}
188-
189169
std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
190170
const SymbolIndex *Index) {
191171
const auto &SM = AST.getSourceManager();

clang-tools-extra/clangd/XRefs.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &, const LocatedSymbol &);
4949
std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
5050
const SymbolIndex *Index = nullptr);
5151

52-
/// Get all document links
53-
std::vector<DocumentLink> getDocumentLinks(ParsedAST &AST);
54-
5552
/// Returns highlights for all usages of a symbol at \p Pos.
5653
std::vector<DocumentHighlight> findDocumentHighlights(ParsedAST &AST,
5754
Position Pos);

clang-tools-extra/clangd/test/document-link.test

Lines changed: 0 additions & 42 deletions
This file was deleted.

clang-tools-extra/clangd/test/initialize-params.test

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
# CHECK-NEXT: "definitionProvider": true,
1919
# CHECK-NEXT: "documentFormattingProvider": true,
2020
# CHECK-NEXT: "documentHighlightProvider": true,
21-
# CHECK-NEXT: "documentLinkProvider": {
22-
# CHECK-NEXT: "resolveProvider": false
23-
# CHECK-NEXT: }
2421
# CHECK-NEXT: "documentOnTypeFormattingProvider": {
2522
# CHECK-NEXT: "firstTriggerCharacter": "\n",
2623
# CHECK-NEXT: "moreTriggerCharacter": []

clang-tools-extra/clangd/unittests/XRefsTests.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,27 +1121,6 @@ TEST(GetNonLocalDeclRefs, All) {
11211121
}
11221122
}
11231123

1124-
TEST(DocumentLinks, All) {
1125-
Annotations MainCpp(R"cpp(
1126-
#include $foo[["foo.h"]]
1127-
int end_of_preamble = 0;
1128-
#include $bar[["bar.h"]]
1129-
)cpp");
1130-
1131-
TestTU TU;
1132-
TU.Code = MainCpp.code();
1133-
TU.AdditionalFiles = {{"foo.h", ""}, {"bar.h", ""}};
1134-
auto AST = TU.build();
1135-
1136-
EXPECT_THAT(
1137-
clangd::getDocumentLinks(AST),
1138-
ElementsAre(
1139-
DocumentLink({MainCpp.range("foo"),
1140-
URIForFile::canonicalize(testPath("foo.h"), "")}),
1141-
DocumentLink({MainCpp.range("bar"),
1142-
URIForFile::canonicalize(testPath("bar.h"), "")})));
1143-
}
1144-
11451124
} // namespace
11461125
} // namespace clangd
11471126
} // namespace clang

0 commit comments

Comments
 (0)