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

How to disable auto import in eclipse java jdt #224

Closed
GNSubrahmanyam opened this issue Jul 11, 2020 · 22 comments
Closed

How to disable auto import in eclipse java jdt #224

GNSubrahmanyam opened this issue Jul 11, 2020 · 22 comments

Comments

@GNSubrahmanyam
Copy link

@rcjsuen In our use case we want to disable autoimport. How to stop sending completionItem/resolve

image

@rcjsuen
Copy link
Collaborator

rcjsuen commented Jul 11, 2020

@GNSubrahmanyam Either use a middleware to intercept the request or change the CompletionOptions from the server so that you make it seem like it actually doesn't support the resolveProvider.

You can look at microsoft/vscode-languageserver-node#322 or microsoft/vscode-languageserver-node#628 for some middleware examples I guess.

@GNSubrahmanyam
Copy link
Author

I tried using middleware to intercept the request but still auto import is happening in Java eclipse language server

@rcjsuen
Copy link
Collaborator

rcjsuen commented Jul 11, 2020

@GNSubrahmanyam What does your middleware code look like?

Whenever you ask for help, you should always share your code if at all possible.

@GNSubrahmanyam
Copy link
Author

@rcjsuen I did that

resolveCompletionItem: (items, token, next) => {
console.log(items)
next({}, token)
},

@rcjsuen
Copy link
Collaborator

rcjsuen commented Jul 11, 2020

resolveCompletionItem: (items, token, next) => {
console.log(items)
next({}, token)
},

I'm surprised the language server hasn't died since you're sending nothing back. You don't want to talk to the server at all, right? Why are you calling next?

@GNSubrahmanyam
Copy link
Author

I agree with you even i am surpised that language server hasn't died :D. I tried removing next call but still autoimport is happening and that's strange

image

@rcjsuen
Copy link
Collaborator

rcjsuen commented Jul 11, 2020

@GNSubrahmanyam Then you need to keep debugging to see what's going on and/or reach out to the JDT Language Server team.

@GNSubrahmanyam
Copy link
Author

GNSubrahmanyam commented Jul 13, 2020

@rcjsuen eclipse-jdtls/eclipse.jdt.ls#1505. In JDT language server no option to disable auto import

@rcjsuen
Copy link
Collaborator

rcjsuen commented Jul 13, 2020

@rcjsuen eclipse/eclipse.jdt.ls#1505. In JDT language server no option to disable auto import

Oh, that's too bad.

@GNSubrahmanyam
Copy link
Author

Any alternative way to prevent via client middleware or server middleware.

@rcjsuen
Copy link
Collaborator

rcjsuen commented Jul 13, 2020

Any alternative way to prevent via client middleware or server middleware.

@GNSubrahmanyam Well, did you figure out where the auto-imports are coming from?

@GNSubrahmanyam
Copy link
Author

image
image
Yes, Through additionalTextEdits

@rcjsuen
Copy link
Collaborator

rcjsuen commented Jul 13, 2020

@GNSubrahmanyam OK, did you try deleting them then?

@GNSubrahmanyam
Copy link
Author

Will try. How can i modifiy the request from lsp backend?

@rcjsuen
Copy link
Collaborator

rcjsuen commented Jul 13, 2020

@GNSubrahmanyam You can just modify the result in your middleware, no?

@GNSubrahmanyam
Copy link
Author

in middleware which method ?

@GNSubrahmanyam
Copy link
Author

GNSubrahmanyam commented Jul 13, 2020

@rcjsuen did this and it is working

import { has, get, map, omit, set} from "lodash";
import * as rpc from "vscode-ws-jsonrpc";
export const launch = (request: http.IncomingMessage, socket: rpc.IWebSocket) => {
if (rpc.isResponseMessage(message)) {
          if (typeof message.result === 'object' && has(message.result, 'isIncomplete')) {
            let items = map(get(message.result, 'items'), (item) => {
              if (has(item, 'additionalTextEdits')) {
                item = omit(item, 'additionalTextEdits')
                return item;
              }
              return item;
            })

            set(message.result, 'items', items)

          }
        }

@rcjsuen
Copy link
Collaborator

rcjsuen commented Jul 13, 2020

@GNSubrahmanyam Thank you for sharing your solution! OK to close this?

@GNSubrahmanyam GNSubrahmanyam changed the title How to stop sending completionItem/resolve How to disable auto import in eclipse java jdt Jul 13, 2020
@GNSubrahmanyam
Copy link
Author

@rcjsuen Thanks :)

@Gilwe
Copy link

Gilwe commented Jan 26, 2021

@GNSubrahmanyam how did you connect the server side of monaco-languageclient to the java language server?

In python i've done it by pip instal pyls and changed in the server side of languageclient:

const serverConnection = bridgeServer.createServerProcess('python','pyls');

How is it done in Java?

@amitbkumar
Copy link

Hey @Gilwe, did you get solution?

@GNSubrahmanyam how did you connect the server side of monaco-languageclient to the java language server?

In python i've done it by pip instal pyls and changed in the server side of languageclient:

const serverConnection = bridgeServer.createServerProcess('python','pyls');

How is it done in Java?

@CGNonofr
Copy link
Collaborator

CGNonofr commented Jul 21, 2021

Their documentation is pretty exhaustive

just run the provided command line instead of python pyls

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

No branches or pull requests

5 participants