emacs-lsp / lsp-java

lsp-mode :heart: java
https://emacs-lsp.github.io/lsp-java
GNU General Public License v3.0
647 stars 90 forks source link

Hangs in "Main thread is Waiting" in tree sitter mode (java-ts-mode) #447

Closed CodyRude closed 1 year ago

CodyRude commented 1 year ago

Describe the bug Stuck on "Main thread is waiting" when using java-ts-mode (tree sitter mode) now available in Emacs 29. Using standard java-mode seems to work.

To Reproduce Get tree-sitter grammer for java libtree-sitter-java.so and place in ~/.emacs.d/tree-sitter/ emacs -Q

(package-initialize)

(require 'lsp-mode)
(require 'lsp-java)

(setq major-mode-remap-alist ())
(add-to-list 'major-mode-remap-alist '(java-mode . java-ts-mode))
(add-hook 'java-ts-mode-hook #'lsp)

open test java file

Expected behavior lsp server will initialize and start working

Logs

Params: {
  "processId": 27144,
  "rootPath": "/data1/Code/mage/problem0034",
  "clientInfo": {
    "name": "emacs",
    "version": "GNU Emacs 29.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.17.8)"
  },
  "rootUri": "file:///data1/Code/mage/problem0034",
  "capabilities": {
    "general": {
      "positionEncodings": [
        "utf-32",
        "utf-16"
      ]
    },
    "workspace": {
      "workspaceEdit": {
        "documentChanges": true,
        "resourceOperations": [
          "create",
          "rename",
          "delete"
        ]
      },
      "applyEdit": true,
      "symbol": {
        "symbolKind": {
          "valueSet": [
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            12,
            13,
            14,
            15,
            16,
            17,
            18,
            19,
            20,
            21,
            22,
            23,
            24,
            25,
            26
          ]
        }
      },
      "executeCommand": {
        "dynamicRegistration": false
      },
      "didChangeWatchedFiles": {
        "dynamicRegistration": true
      },
      "workspaceFolders": true,
      "configuration": true,
      "codeLens": {
        "refreshSupport": true
      },
      "fileOperations": {
        "didCreate": false,
        "willCreate": false,
        "didRename": true,
        "willRename": true,
        "didDelete": false,
        "willDelete": false
      }
    },
    "textDocument": {
      "declaration": {
        "dynamicRegistration": true,
        "linkSupport": true
      },
      "definition": {
        "dynamicRegistration": true,
        "linkSupport": true
      },
      "references": {
        "dynamicRegistration": true
      },
      "implementation": {
        "dynamicRegistration": true,
        "linkSupport": true
      },
      "typeDefinition": {
        "dynamicRegistration": true,
        "linkSupport": true
      },
      "synchronization": {
        "willSave": true,
        "didSave": true,
        "willSaveWaitUntil": true
      },
      "documentSymbol": {
        "symbolKind": {
          "valueSet": [
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9,
            10,
            11,
            12,
            13,
            14,
            15,
            16,
            17,
            18,
            19,
            20,
            21,
            22,
            23,
            24,
            25,
            26
          ]
        },
        "hierarchicalDocumentSymbolSupport": true
      },
      "formatting": {
        "dynamicRegistration": true
      },
      "rangeFormatting": {
        "dynamicRegistration": true
      },
      "onTypeFormatting": {
        "dynamicRegistration": true
      },
      "rename": {
        "dynamicRegistration": true,
        "prepareSupport": true
      },
      "codeAction": {
        "dynamicRegistration": true,
        "isPreferredSupport": true,
        "codeActionLiteralSupport": {
          "codeActionKind": {
            "valueSet": [
              "",
              "quickfix",
              "refactor",
              "refactor.extract",
              "refactor.inline",
              "refactor.rewrite",
              "source",
              "source.organizeImports"
            ]
          }
        },
        "resolveSupport": {
          "properties": [
            "edit",
            "command"
          ]
        },
        "dataSupport": true
      },
      "completion": {
        "completionItem": {
          "snippetSupport": true,
          "documentationFormat": [
            "markdown",
            "plaintext"
          ],
          "resolveAdditionalTextEditsSupport": true,
          "insertReplaceSupport": true,
          "deprecatedSupport": true,
          "resolveSupport": {
            "properties": [
              "documentation",
              "detail",
              "additionalTextEdits",
              "command"
            ]
          },
          "insertTextModeSupport": {
            "valueSet": [
              1,
              2
            ]
          }
        },
        "contextSupport": true,
        "dynamicRegistration": true
      },
      "signatureHelp": {
        "signatureInformation": {
          "parameterInformation": {
            "labelOffsetSupport": true
          }
        },
        "dynamicRegistration": true
      },
      "documentLink": {
        "dynamicRegistration": true,
        "tooltipSupport": true
      },
      "hover": {
        "contentFormat": [
          "markdown",
          "plaintext"
        ],
        "dynamicRegistration": true
      },
      "foldingRange": {
        "dynamicRegistration": true
      },
      "selectionRange": {
        "dynamicRegistration": true
      },
      "callHierarchy": {
        "dynamicRegistration": false
      },
      "typeHierarchy": {
        "dynamicRegistration": true
      },
      "publishDiagnostics": {
        "relatedInformation": true,
        "tagSupport": {
          "valueSet": [
            1,
            2
          ]
        },
        "versionSupport": true
      },
      "linkedEditingRange": {
        "dynamicRegistration": true
      }
    },
    "window": {
      "workDoneProgress": true,
      "showDocument": {
        "support": true
      }
    }
  },
  "initializationOptions": {
    "settings": {
      "java": {
        "errors": {
          "incompleteClasspath": {
            "severity": "warning"
          }
        },
        "dependency": {
          "packagePresentation": "flat"
        },
        "configuration": {
          "checkProjectSettingsExclusions": true,
          "updateBuildConfiguration": "automatic",
          "maven": {
            "notCoveredPluginExecutionSeverity": "warning",
            "defaultMojoExecutionAction": "ignore"
          },
          "workspaceCacheLimit": 90
        },
        "trace": {
          "server": "off"
        },
        "import": {
          "gradle": {
            "enabled": true,
            "wrapper": {
              "enabled": true
            },
            "offline": {
              "enabled": false
            },
            "annotationProcessing": {
              "enabled": true
            }
          },
          "maven": {
            "enabled": true,
            "offline": {
              "enabled": false
            },
            "disableTestClasspathFlag": false
          },
          "exclusions": [
            "**/node_modules/**",
            "**/.metadata/**",
            "**/archetype-resources/**",
            "**/META-INF/maven/**"
          ],
          "generatesMetadataFilesAtProjectRoot": false
        },
        "maven": {
          "downloadSources": false,
          "updateSnapshots": false
        },
        "referencesCodeLens": {
          "enabled": false
        },
        "signatureHelp": {
          "enabled": true,
          "description": {
            "enabled": false
          }
        },
        "implementationsCodeLens": {
          "enabled": false
        },
        "format": {
          "enabled": true,
          "comments": {
            "enabled": true
          },
          "onType": {
            "enabled": true
          },
          "tabSize": "set-from-style"
        },
        "saveActions": {
          "organizeImports": false
        },
        "project": {
          "resourceFilters": [
            "node_modules",
            ".metadata",
            "archetype-resources",
            "META-INF/maven"
          ],
          "referencedLibraries": [
            "lib/**/*.jar"
          ],
          "importOnFirstTimeStartup": "automatic",
          "importHint": true,
          "outputPath": "",
          "encoding": "ignore"
        },
        "autobuild": {
          "enabled": true
        },
        "selectionRange": {
          "enabled": true
        },
        "maxConcurrentBuilds": 1,
        "completion": {
          "enabled": true,
          "overwrite": true,
          "guessMethodArguments": true,
          "favoriteStaticMembers": [
            "org.junit.Assert.*",
            "org.junit.Assume.*",
            "org.junit.jupiter.api.Assertions.*",
            "org.junit.jupiter.api.Assumptions.*",
            "org.junit.jupiter.api.DynamicContainer.*",
            "org.junit.jupiter.api.DynamicTest.*",
            "org.mockito.Mockito.*",
            "org.mockito.ArgumentMatchers.*",
            "org.mockito.Answers.*"
          ],
          "importOrder": [
            "java",
            "javax",
            "com",
            "org"
          ],
          "filteredTypes": [
            "java.awt.*",
            "com.sun.*"
          ],
          "maxResults": 0,
          "postfix": {
            "enabled": true
          },
          "matchCase": "auto",
          "lazyResolveTextEdit": {
            "enabled": false
          }
        },
        "foldingRange": {
          "enabled": true
        },
        "progressReports": {
          "enabled": true
        },
        "codeGeneration": {
          "hashCodeEquals": {
            "useJava7Objects": false,
            "useInstanceof": false
          },
          "useBlocks": false,
          "generateComments": false,
          "toString": {
            "template": "${object.className} [${member.name()}=${member.value}, ${otherMembers}]",
            "codeStyle": "STRING_CONCATENATION",
            "skipNullValues": false,
            "listArrayContents": true,
            "limitElements": 0
          },
          "insertionLocation": "afterCursor"
        },
        "showBuildStatusOnStart": {
          "enabled": false
        },
        "server": {
          "launchMode": "Hybrid"
        },
        "sources": {
          "organizeImports": {
            "starThreshold": 99,
            "staticStarThreshold": 99
          }
        },
        "imports": {
          "gradle": {
            "wrapper": {
              "checksums": []
            }
          }
        },
        "eclipse": {
          "downloadSources": false
        },
        "recommendations": {
          "dependency": {
            "analytics": {
              "show": true
            }
          }
        },
        "references": {
          "includeAccessors": true,
          "includeDecompiledSources": true
        },
        "typeHierarchy": {
          "lazyLoad": false
        },
        "symbols": {
          "includeSourceMethodDeclarations": false
        },
        "quickfix": {
          "showAt": "line"
        },
        "inlayHints": {
          "parameterNames": {
            "enabled": "literals"
          }
        },
        "jdt": {
          "ls": {
            "lombokSupport": {
              "enabled": true
            },
            "protobufSupport": {
              "enabled": true
            },
            "androidSupport": {
              "enabled": "auto"
            }
          }
        },
        "codeAction": {
          "sortMembers": {
            "avoidVolatileChanges": true
          }
        },
        "compile": {
          "nullAnalysis": {
            "nonnull": [
              "javax.annotation.Nonnull",
              "org.eclipse.jdt.annotation.NonNull",
              "org.springframework.lang.NonNull"
            ],
            "nullable": [
              "javax.annotation.Nullable",
              "org.eclipse.jdt.annotation.Nullable",
              "org.springframework.lang.Nullable"
            ],
            "mode": "interactive"
          }
        },
        "sharedIndexes": {
          "enabled": "auto",
          "location": ""
        },
        "refactoring": {
          "extract": {
            "interface": {
              "replace": true
            }
          }
        }
      }
    },
    "extendedClientCapabilities": {
      "progressReportProvider": true,
      "classFileContentsSupport": true,
      "classFileContentsSupport": true,
      "overrideMethodsPromptSupport": true,
      "hashCodeEqualsPromptSupport": true,
      "advancedOrganizeImportsSupport": true,
      "generateConstructorsPromptSupport": true,
      "generateToStringPromptSupport": true,
      "advancedGenerateAccessorsSupport": true,
      "advancedExtractRefactoringSupport": true,
      "moveRefactoringSupport": true,
      "resolveAdditionalTextEditsSupport": true
    },
    "bundles": [
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/com.microsoft.java.test.plugin-0.28.0.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/com.microsoft.jdtls.ext.core-0.5.1.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/dg.jdt.ls.decompiler.cfr-0.0.2-201802221740.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/dg.jdt.ls.decompiler.common-0.0.2-201802221740.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/dg.jdt.ls.decompiler.fernflower-0.0.2-201802221740.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/dg.jdt.ls.decompiler.procyon-0.0.2-201802221740.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/io.projectreactor.reactor-core.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/java.debug.plugin.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/jdt-ls-commons.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/jdt-ls-extension.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.apiguardian_1.1.0.v20190826-0900.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.eclipse.jdt.junit4.runtime_1.1.1200.v20200214-0716.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.eclipse.jdt.junit5.runtime_1.0.900.v20200513-0617.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.jupiter.api_5.6.0.v20200203-2009.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.jupiter.engine_5.6.0.v20200203-2009.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.jupiter.migrationsupport_5.6.0.v20200203-2009.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.jupiter.params_5.6.0.v20200203-2009.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.platform.commons_1.6.0.v20200203-2009.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.platform.engine_1.6.0.v20200203-2009.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.platform.launcher_1.6.0.v20200203-2009.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.platform.runner_1.6.0.v20200203-2009.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.platform.suite.api_1.6.0.v20200203-2009.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.junit.vintage.engine_5.6.0.v20200203-2009.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.opentest4j_1.2.0.v20190826-0900.jar",
      "/home/rude/.emacs.d/.cache/lsp/eclipse.jdt.ls/bundles/org.reactivestreams.reactive-streams.jar"
    ],
    "workspaceFolders": [
      "file:///data1/Code/mage/problem0034",
      "file:///data1/Code/mage/goblins/goblinshared",
      "file:///home/rude/cloud/Code/Goblins/GoblinsServer",
      "file:///data1/Code/mage/countdownmath",
      "file:///data1/Code/mage/problem0041",
      "file:///home/rude/cloud/Code/Euler/problem0032/src/main/java/org/mage/problem0032",
      "file:///data1/Code/mage/problem0036/src/main/java/org/mage/problem0036",
      "file:///data1/Code/mage/problem0035",
      "file:///home/rude/cloud/Code/Euler/problem0037",
      "file:///data1/Code/mage/mathutil",
      "file:///home/rude/cloud/Code/Euler/problem0036",
      "file:///data1/Code/mage/problem0023",
      "file:///data1/Code/mage/problem0033"
    ]
  },
  "workDoneToken": "1",
  "workspaceFolders": [
    {
      "uri": "file:///data1/Code/mage/problem0034",
      "name": "problem0034"
    },
    {
      "uri": "file:///data1/Code/mage/goblins/goblinshared",
      "name": "goblinshared"
    },
    {
      "uri": "file:///home/rude/cloud/Code/Goblins/GoblinsServer",
      "name": "GoblinsServer"
    },
    {
      "uri": "file:///data1/Code/mage/countdownmath",
      "name": "countdownmath"
    },
    {
      "uri": "file:///data1/Code/mage/problem0041",
      "name": "problem0041"
    },
    {
      "uri": "file:///home/rude/cloud/Code/Euler/problem0032/src/main/java/org/mage/problem0032",
      "name": "problem0032"
    },
    {
      "uri": "file:///data1/Code/mage/problem0036/src/main/java/org/mage/problem0036",
      "name": "problem0036"
    },
    {
      "uri": "file:///data1/Code/mage/problem0035",
      "name": "problem0035"
    },
    {
      "uri": "file:///home/rude/cloud/Code/Euler/problem0037",
      "name": "problem0037"
    },
    {
      "uri": "file:///data1/Code/mage/mathutil",
      "name": "mathutil"
    },
    {
      "uri": "file:///home/rude/cloud/Code/Euler/problem0036",
      "name": "problem0036"
    },
    {
      "uri": "file:///data1/Code/mage/problem0023",
      "name": "problem0023"
    },
    {
      "uri": "file:///data1/Code/mage/problem0033",
      "name": "problem0033"
    }
  ]
}

[Trace - 08:21:10 PM] Received notification 'window/logMessage'.
Params: {
  "type": 3,
  "message": "Aug 11, 2023, 8:21:10 PM Main thread is waiting"
}
huangfeiyu commented 1 year ago

I encountered the same issue. @CodyRude have you tried (lsp-semantic-tokens-enable t)? By toggle this on, java-ts-mode is no longer needed. However, I feel the highlight provided by jdtls is confusing and inconsistent. The colors don't make sense to me. Let me show you a screen shot. image

CodyRude commented 1 year ago

Hi @huangfeiyu

I get similar results when I use lsp-semantic-tokens-enable, the highlighting is a little confusing. For now, I can continue using the old java-mode. I just struggle with it sometimes, and was hoping the new java-ts-mode would be cleaner.

thanhvg commented 1 year ago

Try this:

(setq lsp-java-format-tab-size 4)

Then restart lsp server.

If it works for you then I can push a fix.

CodyRude commented 1 year ago

Try this:

(setq lsp-java-format-tab-size 4)

Then restart lsp server.

If it works for you then I can push a fix.

Yep, that fixes it. Thank you!!

marasenna commented 1 year ago

@thanhvg

Try this:

(setq lsp-java-format-tab-size 4)

Then restart lsp server.

If it works for you then I can push a fix.

It fixed the launching issue for me too. However, it broke jdtls' snippet expansion (#449). Setting it back to its default value and switching to java-mode doesn't help. I have noticed that sometimes it starts working correctly until you restart emacs or lsp.

Upd: I'm sorry for this confusion. The problem was with the .emacs.d/.cache/lsp/eclipse.jdt.ls, which I updated by reinstalling it when I tried to get lsp-java work with java-ts-mode. Manually downloaded jdtls 1.26.0 milestone works as intended.