xref: /llvm-project/mlir/include/mlir/AsmParser/CodeComplete.h (revision c60b897d22b2feab3282c4fc2b390bc87560c7de)
1 //===- CodeComplete.h - MLIR Asm CodeComplete Context -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef MLIR_ASMPARSER_CODECOMPLETE_H
10 #define MLIR_ASMPARSER_CODECOMPLETE_H
11 
12 #include "mlir/Support/LLVM.h"
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/Support/SourceMgr.h"
15 
16 namespace mlir {
17 class Attribute;
18 class Type;
19 
20 /// This class provides an abstract interface into the parser for hooking in
21 /// code completion events. This class is only really useful for providing
22 /// language tooling for MLIR, general clients should not need to use this
23 /// class.
24 class AsmParserCodeCompleteContext {
25 public:
26   virtual ~AsmParserCodeCompleteContext();
27 
28   /// Return the source location used to provide code completion.
getCodeCompleteLoc()29   SMLoc getCodeCompleteLoc() const { return codeCompleteLoc; }
30 
31   //===--------------------------------------------------------------------===//
32   // Completion Hooks
33   //===--------------------------------------------------------------------===//
34 
35   /// Signal code completion for a dialect name, with an optional prefix.
36   virtual void completeDialectName(StringRef prefix) = 0;
completeDialectName()37   void completeDialectName() { completeDialectName(""); }
38 
39   /// Signal code completion for an operation name within the given dialect.
40   virtual void completeOperationName(StringRef dialectName) = 0;
41 
42   /// Append the given SSA value as a code completion result for SSA value
43   /// completions.
44   virtual void appendSSAValueCompletion(StringRef name,
45                                         std::string typeData) = 0;
46 
47   /// Append the given block as a code completion result for block name
48   /// completions.
49   virtual void appendBlockCompletion(StringRef name) = 0;
50 
51   /// Signal a completion for the given expected tokens, which are optional if
52   /// `optional` is set.
53   virtual void completeExpectedTokens(ArrayRef<StringRef> tokens,
54                                       bool optional) = 0;
55 
56   /// Signal a completion for an attribute.
57   virtual void completeAttribute(const llvm::StringMap<Attribute> &aliases) = 0;
58   virtual void completeDialectAttributeOrAlias(
59       const llvm::StringMap<Attribute> &aliases) = 0;
60 
61   /// Signal a completion for a type.
62   virtual void completeType(const llvm::StringMap<Type> &aliases) = 0;
63   virtual void
64   completeDialectTypeOrAlias(const llvm::StringMap<Type> &aliases) = 0;
65 
66 protected:
67   /// Create a new code completion context with the given code complete
68   /// location.
AsmParserCodeCompleteContext(SMLoc codeCompleteLoc)69   explicit AsmParserCodeCompleteContext(SMLoc codeCompleteLoc)
70       : codeCompleteLoc(codeCompleteLoc) {}
71 
72 private:
73   /// The location used to code complete.
74   SMLoc codeCompleteLoc;
75 };
76 } // namespace mlir
77 
78 #endif // MLIR_ASMPARSER_CODECOMPLETE_H
79