aya-dev icon indicating copy to clipboard operation
aya-dev copied to clipboard

How to implement completion?

Open ice1000 opened this issue 4 years ago • 26 comments
trafficstars

As title. I'm quite unsure how to do this..

ice1000 avatar May 25 '21 04:05 ice1000

We may need to implement aya-prover/aya-prover-proto#508 first because we should be able to provide completions on incomplete programs IMO

imkiva avatar May 26 '21 06:05 imkiva

But the biggest problem is that our parser currently cannot recover from parse errors like

def test => zero
def a =>  

So when vscode is trying to request completions in a, we can do nothing because parser produces no results :(

imkiva avatar May 26 '21 06:05 imkiva

@imkiva We can just define the syntax better to make these code parse

ice1000 avatar May 26 '21 06:05 ice1000

@imkiva For example, we can make a "definition without body" a type error instead of a parse error

ice1000 avatar May 26 '21 06:05 ice1000

@imkiva For example, we can make a "definition without body" a type error instead of a parse error

This sounds very unlike a type error

re-xyr avatar May 26 '21 06:05 re-xyr

@imkiva For example, we can make a "definition without body" a type error instead of a parse error

This sounds very unlike a type error

It can be thrown as a type error and the users would see a syntax error

ice1000 avatar May 26 '21 06:05 ice1000

Btw how does Arend solve this?

re-xyr avatar May 26 '21 06:05 re-xyr

Btw how does Arend solve this?

Their JB plugin uses a different parser which is fault-tolerant (JB has a general framework for code completion).

ice1000 avatar May 26 '21 06:05 ice1000

Can we have some fault-tolerant parser?

re-xyr avatar May 26 '21 07:05 re-xyr

@ice1000 But this does not cover all cases and we need to change every pass in the compiler every time the syntax compromises.

imkiva avatar May 26 '21 07:05 imkiva

It seems ANTLR4 can recover: https://www.antlr.org/api/Java/org/antlr/v4/runtime/ANTLRErrorStrategy.html

imkiva avatar May 26 '21 07:05 imkiva

Can we have some fault-tolerant parser?

Idk if you could reuse GK

ice1000 avatar May 26 '21 07:05 ice1000

It seems ANTLR4 can recover: https://www.antlr.org/api/Java/org/antlr/v4/runtime/ANTLRErrorStrategy.html

Is that easy to adapt in Aya?

ice1000 avatar May 26 '21 07:05 ice1000

It seems ANTLR4 can recover: https://www.antlr.org/api/Java/org/antlr/v4/runtime/ANTLRErrorStrategy.html

Is that easy to adapt in Aya?

It's a little difficult. ANTLR does not have detailed documents on this.

imkiva avatar May 27 '21 01:05 imkiva

I saw about tree-sitter. Is that any helpful for our case?

re-xyr avatar May 27 '21 06:05 re-xyr

@re-xyr It doesn't have a good Java rewrite/binding yet. JetBrains has a JNI-based binding, but I ain't sure if it's open sourced or "good" in any sense.

ice1000 avatar May 27 '21 06:05 ice1000

It seems ANTLR4 can recover: https://www.antlr.org/api/Java/org/antlr/v4/runtime/ANTLRErrorStrategy.html

Is that easy to adapt in Aya?

It's a little difficult. ANTLR does not have detailed documents on this.

org.antlr.v4.runtime.Parser#setErrorHandler(ANTLRErrorStrategy handler)

ice1000 avatar May 27 '21 06:05 ice1000

image

Quite easy.

ice1000 avatar May 27 '21 06:05 ice1000

image

Quite easy.

I mean these magic functions not the API

image

imkiva avatar May 27 '21 10:05 imkiva

image

Maybe we can just look at the default implementation

ice1000 avatar May 27 '21 13:05 ice1000

image This is what I see. They're heavily documented

ice1000 avatar May 27 '21 13:05 ice1000

I don’t know much about incremental compiling. If we are to offer ide support, are we going to do that anyway? Is ANTLR a capable parser of that? How would we adapt our typechecking process for that?

re-xyr avatar Jun 03 '21 12:06 re-xyr

@re-xyr I have no idea. Probably we should only implement file-level incremental compilation as Agda to avoid the complications

ice1000 avatar Jun 03 '21 14:06 ice1000

/cc @ShreckYe

ice1000 avatar Oct 17 '21 08:10 ice1000

Our parsers are decoupled from base module now. Should we introduce a tree-sitter for LSP only?

imkiva avatar Feb 17 '22 06:02 imkiva

The problem is that there isn't a reliable tree-sitter implementation for JVM. IIRC fleet uses their own binding, which I consider reliable, but it's not open sourced

ice1000 avatar Feb 17 '22 15:02 ice1000