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

psalm-language-server: Method Psalm\\Internal\\LanguageServer\\Server\\TextDocument::documentHighlight() does not exist #10397

Closed
hexmode opened this issue Nov 22, 2023 · 11 comments · Fixed by #10408
Assignees

Comments

@hexmode
Copy link
Contributor

hexmode commented Nov 22, 2023

Installed in emacs, moving my cursor to a problematic line ends up with the following output in my eglot buffer:

[server-reply] (id:3) ERROR Wed Nov 22 09:36:10 2023:
(:jsonrpc "2.0" :id 3 :error
		  (:message "Method Psalm\\Internal\\LanguageServer\\Server\\TextDocument::documentHighlight() does not exist"
					:code -32601 :data nil))
[internal] (id:3) ERROR Wed Nov 22 09:36:10 2023:
(:message
 "error ignored, status set (Method Psalm\\Internal\\LanguageServer\\Server\\TextDocument::documentHighlight() does not exist)"
 :id 3 :error -32601)

Entire buffer:

[internal] Wed Nov 22 09:35:47 2023:
(:message "Running language server: /home/mah/bin/psalm-language-server")
[client-request] (id:1) Wed Nov 22 09:35:47 2023:
(:jsonrpc "2.0" :id 1 :method "initialize" :params
   	  (:processId 2623523 :clientInfo (:name "Eglot" :version "1.15") :rootPath "/home/mah/work/code/psalter-test/"
   				  :rootUri "file:///home/mah/work/code/psalter-test" :initializationOptions
   				  #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()) :capabilities
   				  (:workspace
   				   (:applyEdit t :executeCommand (:dynamicRegistration :json-false) :workspaceEdit
   							   (:documentChanges t) :didChangeWatchedFiles (:dynamicRegistration t) :symbol
   							   (:dynamicRegistration :json-false) :configuration t :workspaceFolders t)
   				   :textDocument
   				   (:synchronization (:dynamicRegistration :json-false :willSave t :willSaveWaitUntil t :didSave t)
   									 :completion
   									 (:dynamicRegistration :json-false :completionItem
   														   (:snippetSupport :json-false :deprecatedSupport t
   																			:resolveSupport
   																			(:properties
   																			 ["documentation" "details"
   																			  "additionalTextEdits"])
   																			:tagSupport (:valueSet [1]))
   														   :contextSupport t)
   									 :hover
   									 (:dynamicRegistration :json-false :contentFormat ["markdown" "plaintext"])
   									 :signatureHelp
   									 (:dynamicRegistration :json-false :signatureInformation
   														   (:parameterInformation (:labelOffsetSupport t)
   																				  :documentationFormat
   																				  ["markdown" "plaintext"]
   																				  :activeParameterSupport t))
   									 :references (:dynamicRegistration :json-false) :definition
   									 (:dynamicRegistration :json-false :linkSupport t) :declaration
   									 (:dynamicRegistration :json-false :linkSupport t) :implementation
   									 (:dynamicRegistration :json-false :linkSupport t) :typeDefinition
   									 (:dynamicRegistration :json-false :linkSupport t) :documentSymbol
   									 (:dynamicRegistration :json-false :hierarchicalDocumentSymbolSupport t
   														   :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]))
   									 :documentHighlight (:dynamicRegistration :json-false) :codeAction
   									 (:dynamicRegistration :json-false :resolveSupport
   														   (:properties ["edit" "command"]) :dataSupport t
   														   :codeActionLiteralSupport
   														   (:codeActionKind
   															(:valueSet
   															 ["quickfix" "refactor" "refactor.extract"
   															  "refactor.inline" "refactor.rewrite" "source"
   															  "source.organizeImports"]))
   														   :isPreferredSupport t)
   									 :formatting (:dynamicRegistration :json-false) :rangeFormatting
   									 (:dynamicRegistration :json-false) :rename (:dynamicRegistration :json-false)
   									 :inlayHint (:dynamicRegistration :json-false) :publishDiagnostics
   									 (:relatedInformation :json-false :codeDescriptionSupport :json-false
   														  :tagSupport (:valueSet [1 2])))
   				   :window (:showDocument (:support t) :workDoneProgress t) :general
   				   (:positionEncodings ["utf-32" "utf-8" "utf-16"]) :experimental
   				   #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()))
   				  :workspaceFolders
   				  [(:uri "file:///home/mah/work/code/psalter-test" :name "~/work/code/psalter-test/")]))
[server-notification] Wed Nov 22 09:35:48 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params
   	  (:type 3 :message "Psalm Language Server 5.x-dev@577808b12da647dd87abb435447dc6429361afdb has started."))
[server-notification] Wed Nov 22 09:35:48 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params (:type 3 :message "Initializing..."))
[server-notification] Wed Nov 22 09:35:48 2023:
(:jsonrpc "2.0" :method "$/progress" :params
   	  (:token "tkn655e11c41d8890.39835496" :value (:kind "begin" :title "Psalm" :message "initializing")))
[server-notification] Wed Nov 22 09:35:48 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params (:type 3 :message "Initializing: Visiting Autoload Files..."))
[server-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params (:type 3 :message "Initializing: Loading Reference Cache..."))
[server-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params (:type 3 :message "Initializing: Initialize Plugins..."))
[server-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params (:type 3 :message "Initializing: Getting code base..."))
[server-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "$/progress" :params
   	  (:token "tkn655e11c41d8890.39835496" :value (:kind "report" :message "getting code base")))
[server-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params (:type 3 :message "Initializing: Scanning files (6 Threads)..."))
[server-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "$/progress" :params
   	  (:token "tkn655e11c41d8890.39835496" :value (:kind "report" :message "scanning files")))
[server-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params (:type 3 :message "Initializing: Registering stub files..."))
[server-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "$/progress" :params
   	  (:token "tkn655e11c41d8890.39835496" :value (:kind "report" :message "registering stub files")))
[server-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params (:type 3 :message "Initializing: Complete."))
[server-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "$/progress" :params
   	  (:token "tkn655e11c41d8890.39835496" :value (:kind "end" :message "initialized")))
[server-reply] (id:1) Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :id 1 :result
   	  (:capabilities
   	   (:textDocumentSync (:openClose t :change 1 :willSave nil :willSaveWaitUntil nil :save (:includeText t))
   						  :hoverProvider t :completionProvider
   						  (:resolveProvider :json-false :triggerCharacters ["$" ">" ":" "[" "(" "," " "])
   						  :signatureHelpProvider (:triggerCharacters ["(" ","]) :definitionProvider t
   						  :typeDefinitionProvider nil :implementationProvider nil :referencesProvider :json-false
   						  :documentHighlightProvider nil :documentSymbolProvider :json-false
   						  :workspaceSymbolProvider :json-false :codeActionProvider nil :codeLensProvider nil
   						  :documentFormattingProvider nil :documentRangeFormattingProvider nil
   						  :documentOnTypeFormattingProvider nil :renameProvider nil :executeCommandProvider nil
   						  :xworkspaceReferencesProvider nil :xdefinitionProvider nil :dependenciesProvider nil)
   	   :serverInfo (:name "Psalm Language Server" :version "5.x-dev@577808b12da647dd87abb435447dc6429361afdb")))
[client-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "initialized" :params
   	  #s(hash-table size 1 test eql rehash-size 1.5 rehash-threshold 0.8125 data ()))
[client-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "textDocument/didOpen" :params
   	  (:textDocument
   	   (:uri "file:///home/mah/work/code/psalter-test/src/Test.php" :version 0 :languageId "php" :text
   			 "<?php\n\nnamespace Hexmode\\Psaltertest;\n\nclas Test {\n}\n")))
[server-request] (id:1) Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :id 1 :method "workspace/configuration" :params (:items [(:section "psalm" :scopeUri nil)]))
[client-reply] (id:1) Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :id 1 :result [nil])
[server-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "telemetry/event" :params (:type 3 :message "running"))
[server-notification] Wed Nov 22 09:35:49 2023:
(:jsonrpc "2.0" :method "textDocument/publishDiagnostics" :params
   	  (:uri "file:///home/mah/work/code/psalter-test/src/Test.php" :diagnostics
   			[(:range (:start (:line 4 :character 5) :end (:line 4 :character 9)) :severity 1 :code 173
   					 :codeDescription nil :source "psalm" :message "Syntax error, unexpected T_STRING on line 5"
   					 :tags nil :relatedInformation nil :data
   					 (:type "ParseError" :snippet "clas Test {" :line_from 5 :line_to 5))
   			 (:range (:start (:line 4 :character 0) :end (:line 4 :character 4)) :severity 1 :code 20
   					 :codeDescription nil :source "psalm" :message "Const clas is not defined" :tags nil
   					 :relatedInformation nil :data
   					 (:type "UndefinedConstant" :snippet "clas Test {" :line_from 5 :line_to 5))]
   			:version 0))
[client-request] (id:2) Wed Nov 22 09:36:10 2023:
(:jsonrpc "2.0" :id 2 :method "textDocument/hover" :params
   	  (:textDocument (:uri "file:///home/mah/work/code/psalter-test/src/Test.php") :position (:line 4 :character 1)))
[client-request] (id:3) Wed Nov 22 09:36:10 2023:
(:jsonrpc "2.0" :id 3 :method "textDocument/documentHighlight" :params
   	  (:textDocument (:uri "file:///home/mah/work/code/psalter-test/src/Test.php") :position (:line 4 :character 1)))
[client-request] (id:4) Wed Nov 22 09:36:10 2023:
(:jsonrpc "2.0" :id 4 :method "textDocument/signatureHelp" :params
   	  (:textDocument (:uri "file:///home/mah/work/code/psalter-test/src/Test.php") :position (:line 4 :character 1)))
[server-reply] (id:2) Wed Nov 22 09:36:10 2023:
(:jsonrpc "2.0" :id 2 :result
   	  (:contents (:kind "markdown" :value "```php\n<?php\n*Hexmode\\Psaltertest-clas\n```") :range
   				 (:start (:line 4 :character 0) :end (:line 4 :character 4))))
[server-notification] Wed Nov 22 09:36:10 2023:
(:jsonrpc "2.0" :method "window/logMessage" :params
   	  (:type 1 :message
   			 "Method Psalm\\Internal\\LanguageServer\\Server\\TextDocument::documentHighlight() does not exist"))
[server-reply] (id:3) ERROR Wed Nov 22 09:36:10 2023:
(:jsonrpc "2.0" :id 3 :error
   	  (:message "Method Psalm\\Internal\\LanguageServer\\Server\\TextDocument::documentHighlight() does not exist"
   				:code -32601 :data nil))
[internal] (id:3) ERROR Wed Nov 22 09:36:10 2023:
(:message
"error ignored, status set (Method Psalm\\Internal\\LanguageServer\\Server\\TextDocument::documentHighlight() does not exist)"
:id 3 :error -32601)
[server-reply] (id:4) Wed Nov 22 09:36:10 2023:
(:jsonrpc "2.0" :id 4 :result nil)
Copy link

Hey @hexmode, can you reproduce the issue on https://psalm.dev ?

hexmode added a commit to hexmode/psalter-test that referenced this issue Nov 22, 2023
@hexmode
Copy link
Contributor Author

hexmode commented Nov 22, 2023

@orklah
Copy link
Collaborator

orklah commented Nov 22, 2023

@tm1000 you may want to look at that

@tm1000
Copy link
Contributor

tm1000 commented Nov 24, 2023

These are just warnings added by @weirdan to let us know which functions to implement.

Depending on the LSP client it could show it as an error because of how it's output but it's not an error and psalm should continue to work as intended

Assign to me and I'll get it added

@tm1000
Copy link
Contributor

tm1000 commented Nov 25, 2023

Looking over the LSP specification we'd have to specifically tell the client we support documentHighlightProvider
(see: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_documentHighlight)

which we don't (it is null, technically undefined)

/**
* Defines how text documents are synced. Is either a detailed structure
* defining each notification or for backwards compatibility the
* TextDocumentSyncKind number. If omitted it defaults to
* `TextDocumentSyncKind.None`.
*/
$serverCapabilities->textDocumentSync = $textDocumentSyncOptions;
/**
* The server provides document symbol support.
* Support "Find all symbols"
*/
$serverCapabilities->documentSymbolProvider = false;
/**
* The server provides workspace symbol support.
* Support "Find all symbols in workspace"
*/
$serverCapabilities->workspaceSymbolProvider = false;
/**
* The server provides goto definition support.
* Support "Go to definition"
*/
$serverCapabilities->definitionProvider = true;
/**
* The server provides find references support.
* Support "Find all references"
*/
$serverCapabilities->referencesProvider = false;
/**
* The server provides hover support.
* Support "Hover"
*/
$serverCapabilities->hoverProvider = true;
/**
* The server provides completion support.
* Support "Completion"
*/
if ($this->project_analyzer->provide_completion) {
$serverCapabilities->completionProvider = new CompletionOptions();
/**
* The server provides support to resolve additional
* information for a completion item.
*/
$serverCapabilities->completionProvider->resolveProvider = false;
/**
* Most tools trigger completion request automatically without explicitly
* requesting it using a keyboard shortcut (e.g. Ctrl+Space). Typically they
* do so when the user starts to type an identifier. For example if the user
* types `c` in a JavaScript file code complete will automatically pop up
* present `console` besides others as a completion item. Characters that
* make up identifiers don't need to be listed here.
*
* If code complete should automatically be trigger on characters not being
* valid inside an identifier (for example `.` in JavaScript) list them in
* `triggerCharacters`.
*/
$serverCapabilities->completionProvider->triggerCharacters = ['$', '>', ':',"[", "(", ",", " "];
}
/**
* Whether code action supports the `data` property which is
* preserved between a `textDocument/codeAction` and a
* `codeAction/resolve` request.
*
* Support "Code Actions" if we support data
*
* @since LSP 3.16.0
*/
if ($this->clientCapabilities->textDocument->publishDiagnostics->dataSupport ?? false) {
$serverCapabilities->codeActionProvider = true;
}
/**
* The server provides signature help support.
*/
$serverCapabilities->signatureHelpProvider = new SignatureHelpOptions(['(', ',']);

Therefore this is an issue with whatever client you are using in emacs. It's not respecting the fact that we don't provide/supply documentHighlightProvider

I have authored #10408 which explicitly tells the client we do not support document highlighting however I believe this is still a client issue because loosely null == false in terms of the LSP

tm1000 added a commit to tm1000/psalm that referenced this issue Nov 25, 2023
Explicitly state that we do not support document highlighting.
@hexmode
Copy link
Contributor Author

hexmode commented Nov 26, 2023

Thanks. That appears to fix this particular issue.

@hexmode
Copy link
Contributor Author

hexmode commented Nov 26, 2023

@tm1000 I checked out your fork and ended up mistakenly filing this bug.

@hexmode
Copy link
Contributor Author

hexmode commented Nov 26, 2023

I checked out master and applied the patch directly to master. Now 'm seeing RuntimeException: PHP Error: Undefined array key "tomorrow" ... . I've captured what eglot is sending to the server in
server-in.log and, using the hexmode/psalter-test repository mentioned above, I'm able to reproduce it using

(cat /tmp/server-in.log; sleep 30) | psalm-language-server > /tmp/server-out.log

Results are in server-out.log.

I'm prepared to file a new issue if you would prefer that.

@tm1000
Copy link
Contributor

tm1000 commented Nov 26, 2023

We don't actively develop against master. You need to use 5.x. That is also where my patch resides and is referenced against.

@hexmode
Copy link
Contributor Author

hexmode commented Nov 26, 2023

Thanks, After struggling with dependencies (and washing the dishes ;) ), patch is working for me on 5.x.

@tm1000
Copy link
Contributor

tm1000 commented Nov 26, 2023

Yeah it's tripped me up a few times too. Master is our "@next" so technically 6.x but doesn't mean it's always working

Thanks for your report and help!

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 a pull request may close this issue.

3 participants