This is an archive of the discontinued LLVM Phabricator instance.

[mlir-lsp] Report range of potential identifier starting at location of diagnostic
ClosedPublic

Authored by jpienaar on Jun 1 2021, 12:13 PM.

Details

Summary

Currently the diagnostics reports the file:line:col, but some LSP frontends
require a non-empty range. Report either the range of an identifier that starts
at location, or a range of 1. Expose the id location to range helper and reuse
here.

Diff Detail

Event Timeline

jpienaar created this revision.Jun 1 2021, 12:13 PM
jpienaar requested review of this revision.Jun 1 2021, 12:13 PM
rriddle requested changes to this revision.Jun 1 2021, 12:20 PM
rriddle added inline comments.
mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
70

I'd rather base this on something real(i.e. heuristically matching a token) than using a magic number.

This revision now requires changes to proceed.Jun 1 2021, 12:20 PM

It would be nice of we could reuse some of the tokenizing logic from the parser to recover the full range. Maybe we could use the ParserAsmState for this injection, and add a method to transform positions into ranges.

jpienaar updated this revision to Diff 349120.Jun 1 2021, 3:39 PM

Expose and reuse convertIdLocToRange heuristic instead of fixed range. Now the range is either that of an identifier that starts at that location or a range of one character if not a valid identifier.

jpienaar retitled this revision from [mlir-lsp] Report arbitrary non-empty range in diagnostics to [mlir-lsp] Report range of potential identifier starting at location of diagnostic.Jun 1 2021, 4:17 PM
jpienaar edited the summary of this revision. (Show Details)
rriddle accepted this revision.Jun 2 2021, 10:08 AM
rriddle added inline comments.
mlir/include/mlir/Parser/AsmParserState.h
109

If this is intended to be just for identifiers, can you rephrase it to indicate that? e.g. ^

mlir/lib/Parser/AsmParserState.cpp
60

nit: None of the other methods here have the description copied from the header.

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

nit: Add a newline before this comment.

This revision is now accepted and ready to land.Jun 2 2021, 10:08 AM
This revision was automatically updated to reflect the committed changes.
jpienaar marked 2 inline comments as done.

Fixing the test (updated incorrectly)