Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completion: add support for keywords like public, class, etc. #21

Open
starbar opened this issue Feb 13, 2020 · 3 comments
Open

Completion: add support for keywords like public, class, etc. #21

starbar opened this issue Feb 13, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@starbar
Copy link

starbar commented Feb 13, 2020

To test the completion function of the server, I run the java file groovy-language-server/src/test/java/net/prominic/groovyls/GroovyServicesCompletionTests.java and successfully output the result. For example, when I let the input content be:

class Completion {
  public Completion() {
    String localVar
    localV

The position (3, 10) will return the label localVar.
However, when I let the input content be:

clas

The position (0, 4) return null,which I think it should return the label class.
And when I let the input content be:

class Completion {
  publi

The position (1, 7) also return null, which I think it should return the label public.
Such situation that the completion result is null is common. So I want to consult why these cases happen and how can I get the ideal completion results.
Looking forward for your answers, thanks!

@joshtynjala
Copy link
Collaborator

joshtynjala commented Feb 13, 2020

I don't think that completion for keywords like class and public has been implemented at this time. It's mostly names of things like variables, functions, and classes.

@joshtynjala joshtynjala added the enhancement New feature or request label Feb 18, 2020
@joshtynjala joshtynjala changed the title Why the completion result is usually null Completion: add support for keywords like public, class, etc. Feb 18, 2020
@starbar
Copy link
Author

starbar commented Feb 21, 2020

Except for the keyword like public, class, etc, some situations about the completion for local variable also return null, like the following cases.

Case 1:

\*content*\
class Completion {
  public Completion(){ 
    String localVar
        localV

\*position*\
(3, 14)  \\The position after "localV"
    
\*output label*\
localVar


\*Null Return Situation*\
\*content*\
class Completion {
    String localVar
        localV

\*position*\
(2, 14)  \\The position after "localV"
    
\*output label*\
null 

In the Case 1, deleting the code snippet public Completion(){ , which seems to have no strong association with the completion request, will cause null return.

Case 2:

\*content*\
class Completion {
  String memberVar{
  public Completion() {
    mem
  }
}

\*position*\
(3, 7)  \\The position after "mem"
    
\*output label*\
memberVar
    

\*Null Return Situation*\
\*content*\
class Completion {
  String memberVar{
  public Completion() {
    mem
  }


\*position*\
(3, 7)  \\The position after "mem"
    
\*output label*\
null

In Case 2, deleting the last { will cause null return. Whether the syntax error will affect the completion result? In fact the Case 1 also has syntax error but the expected label is still returned.

Is there any standard about the completion rules? Or there are some code snippets that I can debug to find its completion rules? Since the project is developed based on many jar packages, it is hard to locate the completion rule of the LSP server.

@joshtynjala
Copy link
Collaborator

joshtynjala commented Feb 21, 2020

Yes, syntax errors can cause completion to fail. The language server uses the Groovy compiler, which expects to receive valid syntax. The language server has a few simple workarounds for basic syntax errors, but it is not comprehensive. Your syntax needs to be mostly correct, including proper brackets for things like classes and methods.

The completion code may be found here in CompletionProvider:

https://github.com/prominic/groovy-language-server/blob/master/src/main/java/net/prominic/groovyls/providers/CompletionProvider.java

Some workarounds for bad syntax may be found here (see the GroovyServices.completion() method):

https://github.com/prominic/groovy-language-server/blob/master/src/main/java/net/prominic/groovyls/GroovyServices.java#L214

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants