diff --git a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp --- a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp +++ b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp @@ -286,7 +286,8 @@ Optional findHover(const lsp::URIForFile &uri, const lsp::Position &hoverPos); Optional - 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 @@ 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 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. diff --git a/mlir/test/mlir-lsp-server/hover.test b/mlir/test/mlir-lsp-server/hover.test --- a/mlir/test/mlir-lsp-server/hover.test +++ b/mlir/test/mlir-lsp-server/hover.test @@ -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"}