This is an archive of the discontinued LLVM Phabricator instance.

[mlir:LSP] Add support for code completing attributes and types
ClosedPublic

Authored by rriddle on Jul 7 2022, 3:12 AM.

Details

Summary

This required changing a bit of how attributes/types are parsed. A new
KeywordSwitch class was added to AsmParser that provides a StringSwitch
like API for parsing keywords with a set of potential matches. It intends to
both provide a cleaner API, and enable injection for code completion. This
required changing the API of generated(Attr|Type)Parser to handle the
parsing of the keyword, instead of having the user do it. Most upstream
dialects use the autogenerated handling and didn't require a direct update.

Depends on D129184

Diff Detail

Event Timeline

rriddle created this revision.Jul 7 2022, 3:12 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
rriddle requested review of this revision.Jul 7 2022, 3:12 AM
jpienaar accepted this revision.Jul 8 2022, 10:30 AM

Thanks!

mlir/include/mlir/IR/OpImplementation.h
679

I would have made this a separate commit as this is a nice feature not LSP related.

mlir/lib/Parser/DialectSymbolParser.cpp
55

Should this be part of Parser's state instead?

mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
705

Could these be queried from registered attributes instead? (could be in future too and TODO )

This revision is now accepted and ready to land.Jul 8 2022, 10:30 AM
rriddle marked 3 inline comments as done.Jul 8 2022, 4:10 PM
rriddle added inline comments.
mlir/lib/Parser/DialectSymbolParser.cpp
55

For now no, given that the isCodeCompletion is only local/used when parsing the immediate attribute/type. I think in the future as we build more complex completions, it might be useful to have it there.

mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
705

Thinking about it, let me add completions for dialects with attributes and types. We can't query the ones here because they are not encoded in the registry, given that builtin attributes/types have special syntax/parsing.

This revision was automatically updated to reflect the committed changes.
rriddle marked 2 inline comments as done.