merrickluo / lsp-tailwindcss

the lsp-mode client for tailwindcss
GNU General Public License v3.0
180 stars 21 forks source link

Request initialize failed with message: Cannot read properties of undefined (reading 'dynamicRegistration') #44

Closed dustinlyons closed 1 year ago

dustinlyons commented 1 year ago

Hello,

I'm seeing the following error after verifying tailwindcss server is installed. The lsp server is unable to start. I'm running Emacs 29.0.50 in Daemon Mode on NixOS.

LSP :: Connected to [volar-api:5162/starting][volar-html:5163/starting][volar-doc:5164/starting][tailwindcss:5166/starting].
LSP :: Error from the Language Server: Request initialize failed with message: Cannot read properties of undefined (reading 'dynamicRegistration') (Internal Error)
LSP :: volar-api:5162 initialized successfully in folders: (/mnt/state/Projects/Code)
LSP :: volar-html:5163 initialized successfully in folders: (/mnt/state/Projects/Code)
LSP :: volar-doc:5164 initialized successfully in folders: (/mnt/state/Projects/Code)

Results of lsp-describe-session:

image

Here is my emacs configuration. I've tried a few things with same results.

  1. Using the package from ELPA by excluding the line with :straight.
  2. lsp-tailwindcss-add-on-mode turned off.
(use-package lsp-tailwindcss
  :straight (:type git :host github :repo "merrickluo/lsp-tailwindcss")
  :init
    (setq lsp-tailwindcss-add-on-mode t))

(use-package web-mode
  :hook (web-mode . lsp-deferred))

(add-to-list 'auto-mode-alist '("\\.jsx?$" . web-mode))
(add-to-list 'auto-mode-alist '("\\.vue\\'" . web-mode))

(defun web-mode-init-hook ()
  "Hooks for Web mode.  Adjust indent."
  (setq web-mode-markup-indent-offset 2))
(add-hook 'web-mode-hook  'web-mode-init-hook)

(straight-use-package
 '(lsp-volar :type git :host github :repo "jadestrong/lsp-volar"))

(use-package lsp-volar)
takueof commented 1 year ago

Hello @merrickluo and @dustinlyons, I have same problem too.

I'm running GNU Emacs 28.1 on macOS from Homebrew. I'm installed lsp-tailwindcss and (setq lsp-tailwindcss-add-on-mode t), the LSP server will run, but it will never finish loading indefinitely.

Please check.

merrickluo commented 1 year ago

Hi, can you please check your language server version with M-x lsp-tailwindcss-installed-server-version? the output from lsp-workspace-show-log would also be helpful.

takueof commented 1 year ago

@merrickluo Thanks for your reply.

Hi, can you please check your language server version with M-x lsp-tailwindcss-installed-server-version? the output from lsp-workspace-show-log would also be helpful.

OK, I tried.

M-x lsp-tailwindcss-installed-server-version

Sorry, that command doesn't show up in the minibuffer...

ScreenShot 2022-09-09 18 30 42

M-x lsp-workspace-show-log

It worked. But all I got was the following message in the minibuffer:

IO logging is disabled

Is there anything else I can do...?

merrickluo commented 1 year ago

i see, ~you need the package to be loaded before running lsp-tailwindcss-installed-server-version, this can be done by opening a file with lsp-tailwindcss enabled~. I probably should autoload it. just realized I didn't make this function interactive, please update and try again.

And about show log, I forgot to mention that you need to toggle it on first with lsp-toggle-trace-io. if you get an error with lsp-tailwindcss-installed-server-version, you should reinstall the server with C-u lsp-install-server and then select tailwindcss.

takueof commented 1 year ago

@merrickluo

I probably should autoload it. just realized I didn't make this function interactive, please update and try again.

Thanks! I installed the latest version (20220910.347) and tried it.

M-x lsp-tailwindcss-installed-server-version

Return 0.8.5.

M-x lsp-workspace-show-log (after M-x lsp-toggle-trace-io)

I chose Workspace: tailwindcss:97266/starting (Timestamp: UTC+9):

[Trace - 02:06:12 PM] Sending notification 'textDocument/didClose'.
Params: {
  "textDocument": {
    "uri": "file:///Users/takueof/test.tsx"
  }
}

This is the only output. I hope this information helps you.

merrickluo commented 1 year ago

Thanks, @takueof, the server version seems good. For the log, can you try another time with the following steps?

  1. turn on logs with lsp-toggle-trace-io
  2. if the server is already started, use lsp-workspace-restart to restart it.

Since the problem is likely on server startup, this is the only way to see the startup logs. It will be great if you can get a minimal example that I can reproduce it, thanks :pray:

takueof commented 1 year ago

@merrickluo Oh, I see. I've attached the log where I tried the following steps:

  1. Turn on lsp-toggle-trace-io
  2. Restart with lsp-workspace-restart
  3. Show logs by lsp-workspace-show-log

M-x lsp-workspace-show-log

[Trace - 09:23:20 AM] Sending request 'initialize - (61)'.
Params: {
  "processId": null,
  "rootPath": "/Users/takueof",
  "clientInfo": {
    "name": "emacs",
    "version": "GNU Emacs 28.1 (build 1, x86_64-apple-darwin21.4.0, Carbon Version 165 AppKit 2113.4)\n of 2022-04-10"
  },
  "rootUri": "file:///Users/takueof",
  "capabilities": {
    "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
      },
      "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
      },
      "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": {
    "configuration": {
      "tailwindCSS": {
        "emmetCompletions": false,
        "showPixelEquivalents": true,
        "rootFontSize": 16,
        "validate": true,
        "hovers": true,
        "suggestions": true,
        "codeActions": true,
        "lint": {
          "invalidScreen": "error",
          "invalidVariant": "error",
          "invalidTailwindDirective": "error",
          "invalidApply": "error",
          "invalidConfigPath": "error",
          "cssConflict": "warning",
          "recommendedVariantOrder": "warning"
        },
        "experimental": {
          "classRegex": ""
        },
        "classAttributes": [
          "class",
          "className",
          "ngClass"
        ]
      }
    }
  },
  "workDoneToken": "1"
}

[Trace - 09:23:20 AM] Received response 'initialize - (61)' in 190ms.
Result: {
  "code": -32603,
  "message": "Request initialize failed with message: Cannot read properties of undefined (reading 'dynamicRegistration')"
}
merrickluo commented 1 year ago

Thank you @takueof. I see, the new version of lsp-mode removed a lot of options related to dynamicRegistration which cause tailwindcss server failed to start, I might need sometime to find out how to workaround this, meanwhile you can pin lsp-mode to an old version if you are able to, I can confirm that "3fa645c0397b8f438f2db2dd288b899ba330d410" works.

takueof commented 1 year ago

@merrickluo Thanks for confirming.

the new version of lsp-mode removed a lot of options related to dynamicRegistration which cause tailwindcss server failed to start, I might need sometime to find out how to workaround this

Oh...😭 I see. I hope you can work around this issue πŸ™

meanwhile you can pin lsp-mode to an old version if you are able to, I can confirm that "3fa645c0397b8f438f2db2dd288b899ba330d410" works.

OK, I'll try to stick with this hash version of lsp-mode.

Best regards.

merrickluo commented 1 year ago

Correction: I misread the diff output, turns out it's lsp-mode is supporting dynamicRegistration now, but it triggered a bug in the language server that didn't check for nil before reading some of the capabilities. I'll send a PR there. https://github.com/tailwindlabs/tailwindcss-intellisense/pull/602

takueof commented 1 year ago

@merrickluo Thank you for creating PR, and congrats on the merge πŸŽ‰ The latest version of Tailwind CSS IntelliSense was just released and the latest version is 0.8.7.

I tried (setq lsp-tailwindcss-server-version "0.8.7"), M-x lsp-update-server (choose tailwindcss) and restart GNU Emacs.

I have confirmed that it works fine! πŸ‘

As for the remaining work, do you just set defcustom's lsp-tailwindcss-server-version to "0.8.7"?

Best regards.

merrickluo commented 1 year ago

Yes, I did test locally too, and hten updated the custom variable, I think we can close this one now, cheers :beer: