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

Disable fallback lsp server #2090

Merged
merged 5 commits into from Feb 25, 2023

Conversation

julienvincent
Copy link
Contributor

@julienvincent julienvincent commented Feb 23, 2023

The clojure-lsp fallback server does not seem to work as expected on Windows machines. It's a bit non-deterministic to test as I was sometimes able to get it to work and sometimes not. There definitely seems to be some behavioural differences though.

The function to start the fallback server has now been changed to return early until support for Windows can be safely added.

Additionally the logic for "always-use-first-workspace-root" now always starts the lsp server in the first project root instead of starting the fallback server if the first project root is not a valid clojure project.

As much as possible the code for working with the fallback server has been left alone in order to facilitate re-enabling these code-paths once Windows support has been figured out.


The issue reported in #2087 talks more about being unable to start the REPL. This I was not able to reproduce at all however my intuition tells me that this was a red herring caused by the Calva extension not booting/initialising (as a result of the fallback server not booting).

The issue with starting the clojure-lsp server in a temp dir seems to be an upstream issue in the clojure-lsp project itself and seems to have something to do with Java path comparisons. See logs:

Server Logs
2023-02-22T00:54:25.183Z  INFO [clojure-lsp.server:592] - [SERVER] Starting server...
2023-02-22T00:54:25.185Z  DEBUG [clojure-lsp.nrepl:21] - nrepl not found, skipping nrepl server start...
2023-02-22T00:54:25.187Z  INFO [clojure-lsp.server:483] - Initializing...
2023-02-22T00:54:25.189Z  ERROR [clojure-lsp.db:73] - [DB] No cache DB file found
2023-02-22T00:54:25.189Z  INFO [clojure-lsp.db:66] - [DB] Reading transit analysis cache from \Users\richa\AppData\Local\Temp\calva-clojure-lsp\.lsp\.cache\db.transit.json db took 0ms
2023-02-22T00:54:29.730Z  INFO [clojure-lsp.source-paths:86] - [Startup] Using default source-paths: ["C:\\Users\\richa\\AppData\\Local\\Temp\\calva-clojure-lsp\\src" "C:\\Users\\richa\\AppData\\Local\\Temp\\calva-clojure-lsp\\test"]
2023-02-22T00:54:29.731Z  INFO [clojure-lsp.startup:114] - Copying kondo configs from classpath to project if any...
2023-02-22T00:54:29.732Z  WARN [clojure-lsp.kondo:306] - Non-fatal error from clj-kondo: No configs copied.
2023-02-22T00:54:29.733Z  INFO [clojure-lsp.startup:116] - Copied kondo configs, took 1ms secs.
2023-02-22T00:54:29.733Z  INFO [clojure-lsp.startup:86] - Analyzing classpath for project root #object[sun.nio.fs.WindowsPath 0x20fc3e24 "\\Users\\richa\\AppData\\Local\\Temp\\calva-clojure-lsp"]
2023-02-22T00:54:29.734Z  ERROR [clojure-lsp.server:55] - Error receiving message: Internal error (-32603)
{:id 0, :method "initialize"}
com.oracle.svm.core.windows.WindowsPlatformThreads.osThreadStartRoutine  WindowsPlatformThreads.java:  143
          com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine         PlatformThreads.java:  705
                                                   java.lang.Thread.run                  Thread.java:  829
                     java.util.concurrent.ThreadPoolExecutor$Worker.run      ThreadPoolExecutor.java:  628
                      java.util.concurrent.ThreadPoolExecutor.runWorker      ThreadPoolExecutor.java: 1128
                                                                    ...                                   
                                      clojure.core.async/thread-call/fn                    async.clj:  484
                                           lsp4clj.server.ChanServer/fn                   server.clj:  209
                                         lsp4clj.server/receive-message                   server.clj:  124
                              lsp4clj.server.ChanServer/receive-request                   server.clj:  265
                                lsp4clj.server/pending-received-request                   server.clj:  177
                                                                    ...                                   
                                                  clojure-lsp.server/fn                   server.clj:  493
                                        clojure-lsp.handlers/initialize                 handlers.clj:  133
                                 clojure-lsp.startup/initialize-project                  startup.clj:  224
                        clojure-lsp.startup/analyze-external-classpath!                  startup.clj:   88
                                                       clojure.core/set                     core.clj: 4114
                                                   clojure.core/reduce1                     core.clj:  932
                                                       clojure.core/seq                     core.clj:  139
                                                                    ...                                   
                                                    clojure.core/map/fn                     core.clj: 2770
                     clojure-lsp.startup/analyze-external-classpath!/fn                  startup.clj:   88
                                 clojure-lsp.shared/relativize-filepath                   shared.clj:  288
                                      sun.nio.fs.WindowsPath.relativize             WindowsPath.java:   42
                                      sun.nio.fs.WindowsPath.relativize             WindowsPath.java:  400
java.lang.IllegalArgumentException: 'other' is different type of Path

With java.lang.IllegalArgumentException: 'other' is different type of Path seeming to be produced when two paths don't share the same root. My guess is that this has something to do with the omission/inclusion of C:\ in some of the paths (see below excerpt) though I don't really know. Maybe @ericdallo can add some insight here?

2023-02-22T00:54:25.189Z  INFO [clojure-lsp.db:66] - [DB] Reading transit analysis cache from \Users\richa\AppData\Local\Temp\calva-clojure-lsp\.lsp\.cache\db.transit.json db took 0ms
2023-02-22T00:54:29.730Z  INFO [clojure-lsp.source-paths:86] - [Startup] Using default source-paths: ["C:\\Users\\richa\\AppData\\Local\\Temp\\calva-clojure-lsp\\src" "C:\\Users\\richa\\AppData\\Local\\Temp\\calva-clojure-lsp\\test"]

Closes #2088
Fixes #2087

Checklist

  • Read How to Contribute.
  • Directed this pull request at the dev branch. (Or have specific reasons to target some other branch.)
  • Made sure I have changed the PR base branch, so that it is not published. (Sorry for the nagging.)
  • Updated the [Unreleased] entry in CHANGELOG.md, linking the issue(s) that the PR is addressing.
  • Figured if anything about the fix warrants tests on Mac/Linux/Windows/Remote/Whatever, and either tested it there if so, or mentioned it in the PR.
  • [ ] Added to or updated docs in this branch, if appropriate
  • Tests
    • Tested the particular change
    • [ ] Figured if the change might have some side effects and tested those as well.
  • Referenced the issue I am fixing/addressing in a commit message for the pull request.
    • If I am fixing the issue, I have used GitHub's fixes/closes syntax
    • [ ] If I am fixing just part of the issue, I have just referenced it w/o any of the "fixes” keywords.
  • [ ] Created the issue I am fixing/addressing, if it was not present.
  • Formatted all JavaScript and TypeScript code that was changed. (use the prettier extension or run npm run prettier-format)
  • Confirmed that there are no linter warnings or errors (use the eslint extension, run npm run eslint before creating your PR, or run npm run eslint-watch to eslint as you go).

The clojure-lsp fallback server does not work as expected on Windows
machines.

The function to start the fallback server has now been changed to return
early until support for Windows can be safely added.

Additionally the logic for `"always-use-first-workspace-root"` now
always starts the lsp server in the first project root instead of
starting the fallback server if the first project root is not a valid
clojure project.

As much as possible the code for working with the fallback server has
been left along in order to facilitate re-enabling these code-paths once
Windows support has been figured out.

Closes BetterThanTomorrow#2088
Fixes BetterThanTomorrow#2087
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@bpringe bpringe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Just updated an issue title in the changelog to match what I changed it to. I'll let @PEZ take a look too before we merge.

@ericdallo
Copy link
Contributor

With java.lang.IllegalArgumentException: 'other' is different type of Path seeming to be produced when two paths don't share the same root. My guess is that this has something to do with the omission/inclusion of C:\ in some of the paths (see below excerpt) though I don't really know. Maybe @ericdallo can add some insight here?

Never saw that exception, but seems like the project-root is not absolute (missing the C:).

@bpringe
Copy link
Member

bpringe commented Feb 25, 2023

The function to start the fallback server has now been changed to return early until support for Windows can be safely added.

@julienvincent I'm guessing that af1761b changed that. Good find. I think we've been bitten by this same issue (or something similar) elsewhere before, unfortunately. Has this been tested on Windows?

By the way, I updated the PR checklist to cross out the unchecked boxes as I'm guessing you left them unchecked because they didn't apply.

@julienvincent
Copy link
Contributor Author

julienvincent commented Feb 25, 2023

@julienvincent I'm guessing that af1761b changed that. Good find. I think we've been bitten by this same issue (or something similar) elsewhere before, unfortunately.

The early return I am referring to here is actually this: 9f61baf#diff-a744c42f2b8787edf067397d52c9ccd6f4f300323d1537b80b92027b3058d7dbR161

The changes from af1761b are fixing a separate issue which was resulting in an infinite loop on Windows (reported on slack).

Never saw that exception, but seems like the project-root is not absolute (missing the C:).

@ericdallo In this case we are starting the lsp server with an absolute path (including the C:). I'm trying to figure out if this is an issue in clojure-lsp and I should raise an issue there/debug it there, or if this is maybe an issue higher up (like in the vscode languageclient lib for example)? What do you think?

The api method for finding an LSP client for a given document URI was
written to stop traversing when encountering the OS root. This logic
assumed POSIX paths and did not work correctly on Windows platforms.

This updates the clojure-lsp client ids to use the uri.fsPath which is
platform agnostic and updates the root path comparison in the lsp api to
compare in a platform agnostic manner.
@julienvincent
Copy link
Contributor Author

Has this been tested on Windows?

@bpringe Yes, this was actually developed on a Windows VM :) And we have the original reporter testing these changes out as we go, which is very helpful.

There is still one more issue reported (see slack thread) which I would like to catch before this can be merged. However I am not really able to reproduce it as of yet.

The `Uri.parse` method is for parsing full URI's that include a 'scheme'
component. Our usage was 'fine' for POSIX systems as it was non-strict
and would fallback to a `file://` scheme however on Windows it would
interpret the leading `C:\` as the scheme.

This commit replaces all our usages of `parse` with `file` where we are
using known file paths to remove this ambiguity.
@julienvincent
Copy link
Contributor Author

There is still one more issue reported (see slack thread) which I would like to catch before this can be merged. However I am not really able to reproduce it as of yet.

Ok this should now be fixed in 5877356 - just waiting on confirmation from the user.

Copy link
Collaborator

@PEZ PEZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@PEZ
Copy link
Collaborator

PEZ commented Feb 25, 2023

Thanks for providing, @julienvincent!

@julienvincent
Copy link
Contributor Author

Cool, @PEZ I think this is good to go unless you can think of anything left to do?

@PEZ PEZ merged commit 60eb522 into BetterThanTomorrow:dev Feb 25, 2023
@PEZ
Copy link
Collaborator

PEZ commented Feb 25, 2023

Releasing now! 🚀

@julienvincent julienvincent deleted the regression/disable-tmp-lsp branch February 25, 2023 11:58
@bpringe
Copy link
Member

bpringe commented Feb 25, 2023

The early return I am referring to here is actually this: 9f61baf#diff-a744c42f2b8787edf067397d52c9ccd6f4f300323d1537b80b92027b3058d7dbR161

Ah, whoops. I had seen that before but I think I was looking at a single commit when I made that comment. Anyway, good stuff here!

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

Successfully merging this pull request may close these issues.

None yet

4 participants