forked from OSchip/llvm-project
[mlir-lsp-server] Add support for hover on symbol references
For now the hover simply shows the same information as hovering on the operation name. If necessary this can be tweaked to something symbol specific later. Differential Revision: https://reviews.llvm.org/D103728
This commit is contained in:
parent
f492c35965
commit
4c3adea7a4
|
@ -286,7 +286,8 @@ struct MLIRDocument {
|
|||
Optional<lsp::Hover> findHover(const lsp::URIForFile &uri,
|
||||
const lsp::Position &hoverPos);
|
||||
Optional<lsp::Hover>
|
||||
buildHoverForOperation(const AsmParserState::OperationDefinition &op);
|
||||
buildHoverForOperation(llvm::SMRange hoverRange,
|
||||
const AsmParserState::OperationDefinition &op);
|
||||
lsp::Hover buildHoverForOperationResult(llvm::SMRange hoverRange,
|
||||
Operation *op, unsigned resultStart,
|
||||
unsigned resultEnd,
|
||||
|
@ -439,7 +440,12 @@ Optional<lsp::Hover> MLIRDocument::findHover(const lsp::URIForFile &uri,
|
|||
for (const AsmParserState::OperationDefinition &op : asmState.getOpDefs()) {
|
||||
// Check if the position points at this operation.
|
||||
if (contains(op.loc, posLoc))
|
||||
return buildHoverForOperation(op);
|
||||
return buildHoverForOperation(op.loc, op);
|
||||
|
||||
// Check if the position points at the symbol name.
|
||||
for (auto &use : op.symbolUses)
|
||||
if (contains(use, posLoc))
|
||||
return buildHoverForOperation(use, op);
|
||||
|
||||
// Check if the position points at a result group.
|
||||
for (unsigned i = 0, e = op.resultGroups.size(); i < e; ++i) {
|
||||
|
@ -473,8 +479,8 @@ Optional<lsp::Hover> MLIRDocument::findHover(const lsp::URIForFile &uri,
|
|||
}
|
||||
|
||||
Optional<lsp::Hover> MLIRDocument::buildHoverForOperation(
|
||||
const AsmParserState::OperationDefinition &op) {
|
||||
lsp::Hover hover(getRangeFromLoc(sourceMgr, op.loc));
|
||||
llvm::SMRange hoverRange, const AsmParserState::OperationDefinition &op) {
|
||||
lsp::Hover hover(getRangeFromLoc(sourceMgr, hoverRange));
|
||||
llvm::raw_string_ostream os(hover.contents.value);
|
||||
|
||||
// Add the operation name to the hover.
|
||||
|
|
|
@ -128,6 +128,30 @@
|
|||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: }
|
||||
// -----
|
||||
{"jsonrpc":"2.0","id":6,"method":"shutdown"}
|
||||
// Hover on a symbol reference.
|
||||
{"jsonrpc":"2.0","id":6,"method":"textDocument/hover","params":{
|
||||
"textDocument":{"uri":"test:///foo.mlir"},
|
||||
"position":{"line":0,"character":8}
|
||||
}}
|
||||
// CHECK: "id": 6,
|
||||
// CHECK-NEXT: "jsonrpc": "2.0",
|
||||
// CHECK-NEXT: "result": {
|
||||
// CHECK-NEXT: "contents": {
|
||||
// CHECK-NEXT: "kind": "markdown",
|
||||
// CHECK-NEXT: "value": "\"func\" : public @foo\n\nGeneric Form:\n\n```mlir\n\"func\"() ( {\n}) {sym_name = \"foo\", type = (i1) -> ()} : () -> ()\n```\n"
|
||||
// CHECK-NEXT: },
|
||||
// CHECK-NEXT: "range": {
|
||||
// CHECK-NEXT: "end": {
|
||||
// CHECK-NEXT: "character": 9,
|
||||
// CHECK-NEXT: "line": 0
|
||||
// CHECK-NEXT: },
|
||||
// CHECK-NEXT: "start": {
|
||||
// CHECK-NEXT: "character": 5,
|
||||
// CHECK-NEXT: "line": 0
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: }
|
||||
// -----
|
||||
{"jsonrpc":"2.0","id":7,"method":"shutdown"}
|
||||
// -----
|
||||
{"jsonrpc":"2.0","method":"exit"}
|
||||
|
|
Loading…
Reference in New Issue