From 0429472efe6a894a6554d75fd77baeb9cdb32dd5 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Sat, 30 Apr 2022 00:32:24 -0700 Subject: [PATCH] [mlir:PDLL] Fix signature help for operation operands We were currently only completing on the first operand because the completion check was outside of the parse loop. Differential Revision: https://reviews.llvm.org/D124784 --- mlir/lib/Tools/PDLL/Parser/Parser.cpp | 12 +- mlir/test/mlir-pdll-lsp-server/include/included.td | 10 +- mlir/test/mlir-pdll-lsp-server/signature-help.test | 154 ++++++++++++++++++++- 3 files changed, 162 insertions(+), 14 deletions(-) diff --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp index 49eaa41..e7ec5a0 100644 --- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp @@ -1982,14 +1982,14 @@ Parser::parseOperationExpr(OpResultTypeContext inputResultTypeContext) { ast::ValueRangeConstraintDecl::create(ctx, loc), valueRangeTy)); } } else if (!consumeIf(Token::r_paren)) { - // Check for operand signature code completion. - if (curToken.is(Token::code_complete)) { - codeCompleteOperationOperandsSignature(opName, operands.size()); - return failure(); - } - // If the operand list was specified and non-empty, parse the operands. do { + // Check for operand signature code completion. + if (curToken.is(Token::code_complete)) { + codeCompleteOperationOperandsSignature(opName, operands.size()); + return failure(); + } + FailureOr operand = parseExpr(); if (failed(operand)) return failure(); diff --git a/mlir/test/mlir-pdll-lsp-server/include/included.td b/mlir/test/mlir-pdll-lsp-server/include/included.td index 881abd0..21ab1b3 100644 --- a/mlir/test/mlir-pdll-lsp-server/include/included.td +++ b/mlir/test/mlir-pdll-lsp-server/include/included.td @@ -1,4 +1,10 @@ include "mlir/IR/OpBase.td" -// This file is merely to test the processing of includes, it has -// no other purpose or contents. +def Test_Dialect : Dialect { + let name = "test"; +} + +def OpMulti : Op { + let arguments = (outs I64:$operand, I64:$operand2); + let results = (outs I64:$result, I64:$result2); +} diff --git a/mlir/test/mlir-pdll-lsp-server/signature-help.test b/mlir/test/mlir-pdll-lsp-server/signature-help.test index 30423ea..d7e88d4 100644 --- a/mlir/test/mlir-pdll-lsp-server/signature-help.test +++ b/mlir/test/mlir-pdll-lsp-server/signature-help.test @@ -1,16 +1,16 @@ -// RUN: mlir-pdll-lsp-server -lit-test < %s | FileCheck -strict-whitespace %s +// RUN: mlir-pdll-lsp-server -pdll-extra-dir %S -pdll-extra-dir %S/../../include -lit-test < %s | FileCheck -strict-whitespace %s {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"pdll","capabilities":{},"trace":"off"}} // ----- {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{ "uri":"test:///foo.pdll", "languageId":"pdll", "version":1, - "text":"Constraint ValueCst(value: Value);\nPattern {\nlet root = op() -> ();\nValueCst(root);\nerase root;\n}" + "text":"#include \"include/included.td\"\nConstraint ValueCst(value: Value, value2: Value);\nPattern {\nlet root = op(val: Value, val) -> (ty: Type, ty);\nValueCst(root.result, root.result2);\nerase root;\n}" }}} // ----- {"jsonrpc":"2.0","id":1,"method":"textDocument/signatureHelp","params":{ "textDocument":{"uri":"test:///foo.pdll"}, - "position":{"line":2,"character":23} + "position":{"line":3,"character":26} }} // CHECK: "id": 1 // CHECK-NEXT: "jsonrpc": "2.0", @@ -19,6 +19,26 @@ // CHECK-NEXT: "activeSignature": 0, // CHECK-NEXT: "signatures": [ // CHECK-NEXT: { +// CHECK-NEXT: "documentation": "`op` ODS operand specification", +// CHECK-NEXT: "label": "(operand: Value, operand2: Value)", +// CHECK-NEXT: "parameters": [ +// CHECK-NEXT: { +// CHECK-NEXT: "documentation": "64-bit signless integer", +// CHECK-NEXT: "label": [ +// CHECK-NEXT: 1, +// CHECK-NEXT: 15 +// CHECK-NEXT: ] +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT: "documentation": "64-bit signless integer", +// CHECK-NEXT: "label": [ +// CHECK-NEXT: 17, +// CHECK-NEXT: 32 +// CHECK-NEXT: ] +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: }, +// CHECK-NEXT: { // CHECK-NEXT: "documentation": "Generic operation operand specification", // CHECK-NEXT: "label": "(: ValueRange)", // CHECK-NEXT: "parameters": [ @@ -36,7 +56,40 @@ // ----- {"jsonrpc":"2.0","id":1,"method":"textDocument/signatureHelp","params":{ "textDocument":{"uri":"test:///foo.pdll"}, - "position":{"line":2,"character":29} + "position":{"line":3,"character":38} +}} +// CHECK: "id": 1 +// CHECK-NEXT: "jsonrpc": "2.0", +// CHECK-NEXT: "result": { +// CHECK-NEXT: "activeParameter": 1, +// CHECK-NEXT: "activeSignature": 0, +// CHECK-NEXT: "signatures": [ +// CHECK-NEXT: { +// CHECK-NEXT: "documentation": "`op` ODS operand specification", +// CHECK-NEXT: "label": "(operand: Value, operand2: Value)", +// CHECK-NEXT: "parameters": [ +// CHECK-NEXT: { +// CHECK-NEXT: "documentation": "64-bit signless integer", +// CHECK-NEXT: "label": [ +// CHECK-NEXT: 1, +// CHECK-NEXT: 15 +// CHECK-NEXT: ] +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT: "documentation": "64-bit signless integer", +// CHECK-NEXT: "label": [ +// CHECK-NEXT: 17, +// CHECK-NEXT: 32 +// CHECK-NEXT: ] +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: } +// ----- +{"jsonrpc":"2.0","id":1,"method":"textDocument/signatureHelp","params":{ + "textDocument":{"uri":"test:///foo.pdll"}, + "position":{"line":3,"character":47} }} // CHECK: "id": 1 // CHECK-NEXT: "jsonrpc": "2.0", @@ -45,6 +98,26 @@ // CHECK-NEXT: "activeSignature": 0, // CHECK-NEXT: "signatures": [ // CHECK-NEXT: { +// CHECK-NEXT: "documentation": "`op` ODS result specification", +// CHECK-NEXT: "label": "(result: Type, result2: Type)", +// CHECK-NEXT: "parameters": [ +// CHECK-NEXT: { +// CHECK-NEXT: "documentation": "64-bit signless integer", +// CHECK-NEXT: "label": [ +// CHECK-NEXT: 1, +// CHECK-NEXT: 13 +// CHECK-NEXT: ] +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT: "documentation": "64-bit signless integer", +// CHECK-NEXT: "label": [ +// CHECK-NEXT: 15, +// CHECK-NEXT: 28 +// CHECK-NEXT: ] +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: }, +// CHECK-NEXT: { // CHECK-NEXT: "documentation": "Generic operation result specification", // CHECK-NEXT: "label": "(: TypeRange)", // CHECK-NEXT: "parameters": [ @@ -62,7 +135,40 @@ // ----- {"jsonrpc":"2.0","id":1,"method":"textDocument/signatureHelp","params":{ "textDocument":{"uri":"test:///foo.pdll"}, - "position":{"line":3,"character":9} + "position":{"line":3,"character":57} +}} +// CHECK: "id": 1 +// CHECK-NEXT: "jsonrpc": "2.0", +// CHECK-NEXT: "result": { +// CHECK-NEXT: "activeParameter": 1, +// CHECK-NEXT: "activeSignature": 0, +// CHECK-NEXT: "signatures": [ +// CHECK-NEXT: { +// CHECK-NEXT: "documentation": "`op` ODS result specification", +// CHECK-NEXT: "label": "(result: Type, result2: Type)", +// CHECK-NEXT: "parameters": [ +// CHECK-NEXT: { +// CHECK-NEXT: "documentation": "64-bit signless integer", +// CHECK-NEXT: "label": [ +// CHECK-NEXT: 1, +// CHECK-NEXT: 13 +// CHECK-NEXT: ] +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT: "documentation": "64-bit signless integer", +// CHECK-NEXT: "label": [ +// CHECK-NEXT: 15, +// CHECK-NEXT: 28 +// CHECK-NEXT: ] +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: } +// ----- +{"jsonrpc":"2.0","id":1,"method":"textDocument/signatureHelp","params":{ + "textDocument":{"uri":"test:///foo.pdll"}, + "position":{"line":4,"character":9} }} // CHECK: "id": 1 // CHECK-NEXT: "jsonrpc": "2.0", @@ -71,13 +177,49 @@ // CHECK-NEXT: "activeSignature": 0, // CHECK-NEXT: "signatures": [ // CHECK-NEXT: { -// CHECK-NEXT: "label": "ValueCst(value: Value) -> Tuple<>", +// CHECK-NEXT: "label": "ValueCst(value: Value, value2: Value) -> Tuple<>", // CHECK-NEXT: "parameters": [ // CHECK-NEXT: { // CHECK-NEXT: "label": [ // CHECK-NEXT: 9, // CHECK-NEXT: 21 // CHECK-NEXT: ] +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT: "label": [ +// CHECK-NEXT: 23, +// CHECK-NEXT: 36 +// CHECK-NEXT: ] +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: } +// CHECK-NEXT: ] +// CHECK-NEXT: } +// ----- +{"jsonrpc":"2.0","id":1,"method":"textDocument/signatureHelp","params":{ + "textDocument":{"uri":"test:///foo.pdll"}, + "position":{"line":4,"character":21} +}} +// CHECK: "id": 1 +// CHECK-NEXT: "jsonrpc": "2.0", +// CHECK-NEXT: "result": { +// CHECK-NEXT: "activeParameter": 1, +// CHECK-NEXT: "activeSignature": 0, +// CHECK-NEXT: "signatures": [ +// CHECK-NEXT: { +// CHECK-NEXT: "label": "ValueCst(value: Value, value2: Value) -> Tuple<>", +// CHECK-NEXT: "parameters": [ +// CHECK-NEXT: { +// CHECK-NEXT: "label": [ +// CHECK-NEXT: 9, +// CHECK-NEXT: 21 +// CHECK-NEXT: ] +// CHECK-NEXT: }, +// CHECK-NEXT: { +// CHECK-NEXT: "label": [ +// CHECK-NEXT: 23, +// CHECK-NEXT: 36 +// CHECK-NEXT: ] // CHECK-NEXT: } // CHECK-NEXT: ] // CHECK-NEXT: } -- 2.7.4