neoclide / coc.nvim

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Other
24.37k stars 956 forks source link

unable to use `:Format` with vscode's solidity language server #4869

Closed sify21 closed 8 months ago

sify21 commented 8 months ago

Result from CocInfo

versions

vim version: VIM - Vi IMproved 9.0 9002121 node version: v18.17.1 coc.nvim version: 0.0.82-d1568d56 2023-09-29 19:43:34 +0800 coc.nvim directory: /home/sify/.vim/plugged/coc.nvim term: dumb platform: linux

Log of coc.nvim

2024-01-23T15:27:55.136 INFO (pid:267368) [plugin] - coc.nvim initialized with node: v18.17.1 after 102

Describe the bug

I registered a custom solidity language server (the one from VSCode https://github.com/juanfranblanco/vscode-solidity), but I can't :Format current buffer in vim. AFAIK this language server supports formatting.

Reproduce the bug

if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
source ~/.vim/coc.nvim

Since I'm using Foundry, you can install it using foundryup https://book.getfoundry.sh/getting-started/installation

The settings part is copied from its integration guide: https://book.getfoundry.sh/config/vscode

{
    "languageserver": {
        "solidity": {
            "command": "vscode-solidity-server",
            "args": [
                "--stdio"
            ],
            "rootPatterns": [
                ".git/"
            ],
            "filetypes": [
                "solidity"
            ],
            "formatterPriority": 0,
            "settings": {
                "solidity.packageDefaultDependenciesContractsDirectory": "src",
                "solidity.packageDefaultDependenciesDirectory": "lib",
                "solidity.formatter": "forge",
                "solidity.defaultCompiler": "localFile",
                "solidity.compileUsingLocalVersion": "solc"
            }
        }
    }
}

contract Counter { uint256 public number;

function setNumber(uint256 newNumber) public {
    number = newNumber;
    address payable a = payable(msg.sender);
}

function increment() public {
    number++;
}

}


- coc reports error

[coc.nvim]: Error on notification "format": Format provider not found for buffer: 1



## Screenshots (optional)

If applicable, add screenshots to help explain your problem.
fannheyward commented 8 months ago

Add "trace.server": "verbose", then :CocCommand workspace.showOutput, choose solidity to see the trace logs, search textDocument/formatting request, what's the response?

sify21 commented 8 months ago

sorry for the late reply, there is no textDocument/formatting request, here is the output

[Trace - 10:09:45.825] Sending request 'initialize - (0)'.
Params: {
    "processId": 329531,
    "rootPath": "/home/sify/Downloads",
    "rootUri": "file:///home/sify/Downloads",
    "capabilities": {
        "workspace": {
            "applyEdit": true,
            "workspaceEdit": {
                "documentChanges": true,
                "resourceOperations": [
                    "create",
                    "rename",
                    "delete"
                ],
                "failureHandling": "undo",
                "normalizesLineEndings": true,
                "changeAnnotationSupport": {
                    "groupsOnLabel": false
                }
            },
            "didChangeConfiguration": {
                "dynamicRegistration": true
            },
            "didChangeWatchedFiles": {
                "dynamicRegistration": true,
                "relativePatternSupport": true
            },
            "codeLens": {
                "refreshSupport": true
            },
            "executeCommand": {
                "dynamicRegistration": true
            },
            "configuration": true,
            "fileOperations": {
                "dynamicRegistration": true,
                "didCreate": true,
                "didRename": true,
                "didDelete": true,
                "willCreate": true,
                "willRename": true,
                "willDelete": true
            },
            "semanticTokens": {
                "refreshSupport": true
            },
            "inlayHint": {
                "refreshSupport": true
            },
            "inlineValue": {
                "refreshSupport": true
            },
            "diagnostics": {
                "refreshSupport": true
            },
            "symbol": {
                "dynamicRegistration": true,
                "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
                    ]
                },
                "tagSupport": {
                    "valueSet": [
                        1
                    ]
                },
                "resolveSupport": {
                    "properties": [
                        "location.range"
                    ]
                }
            },
            "workspaceFolders": true
        },
        "textDocument": {
            "publishDiagnostics": {
                "relatedInformation": true,
                "versionSupport": true,
                "tagSupport": {
                    "valueSet": [
                        1,
                        2
                    ]
                },
                "codeDescriptionSupport": true,
                "dataSupport": true
            },
            "synchronization": {
                "dynamicRegistration": true,
                "willSave": true,
                "willSaveWaitUntil": true,
                "didSave": true
            },
            "completion": {
                "dynamicRegistration": true,
                "contextSupport": true,
                "completionItem": {
                    "snippetSupport": true,
                    "commitCharactersSupport": true,
                    "documentationFormat": [
                        "markdown",
                        "plaintext"
                    ],
                    "deprecatedSupport": true,
                    "preselectSupport": true,
                    "insertReplaceSupport": true,
                    "tagSupport": {
                        "valueSet": [
                            1
                        ]
                    },
                    "resolveSupport": {
                        "properties": [
                            "documentation",
                            "detail",
                            "additionalTextEdits"
                        ]
                    },
                    "labelDetailsSupport": true,
                    "insertTextModeSupport": {
                        "valueSet": [
                            1,
                            2
                        ]
                    }
                },
                "completionItemKind": {
                    "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
                    ]
                },
                "insertTextMode": 2,
                "completionList": {
                    "itemDefaults": [
                        "commitCharacters",
                        "editRange",
                        "insertTextFormat",
                        "insertTextMode"
                    ]
                }
            },
            "hover": {
                "dynamicRegistration": true,
                "contentFormat": [
                    "markdown",
                    "plaintext"
                ]
            },
            "signatureHelp": {
                "dynamicRegistration": true,
                "contextSupport": true,
                "signatureInformation": {
                    "documentationFormat": [
                        "markdown",
                        "plaintext"
                    ],
                    "activeParameterSupport": true,
                    "parameterInformation": {
                        "labelOffsetSupport": true
                    }
                }
            },
            "references": {
                "dynamicRegistration": true
            },
            "definition": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "documentHighlight": {
                "dynamicRegistration": true
            },
            "documentSymbol": {
                "dynamicRegistration": true,
                "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,
                "tagSupport": {
                    "valueSet": [
                        1
                    ]
                },
                "labelSupport": true
            },
            "codeAction": {
                "dynamicRegistration": true,
                "isPreferredSupport": true,
                "disabledSupport": true,
                "dataSupport": true,
                "honorsChangeAnnotations": false,
                "resolveSupport": {
                    "properties": [
                        "edit"
                    ]
                },
                "codeActionLiteralSupport": {
                    "codeActionKind": {
                        "valueSet": [
                            "",
                            "quickfix",
                            "refactor",
                            "refactor.extract",
                            "refactor.inline",
                            "refactor.rewrite",
                            "source",
                            "source.organizeImports"
                        ]
                    }
                }
            },
            "codeLens": {
                "dynamicRegistration": true
            },
            "formatting": {
                "dynamicRegistration": true
            },
            "rangeFormatting": {
                "dynamicRegistration": true
            },
            "onTypeFormatting": {
                "dynamicRegistration": true
            },
            "rename": {
                "dynamicRegistration": true,
                "prepareSupport": true,
                "honorsChangeAnnotations": true,
                "prepareSupportDefaultBehavior": 1
            },
            "documentLink": {
                "dynamicRegistration": true,
                "tooltipSupport": true
            },
            "typeDefinition": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "implementation": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "declaration": {
                "dynamicRegistration": true,
                "linkSupport": true
            },
            "colorProvider": {
                "dynamicRegistration": true
            },
            "foldingRange": {
                "dynamicRegistration": true,
                "rangeLimit": 5000,
                "lineFoldingOnly": true,
                "foldingRangeKind": {
                    "valueSet": [
                        "comment",
                        "imports",
                        "region"
                    ]
                },
                "foldingRange": {
                    "collapsedText": false
                }
            },
            "selectionRange": {
                "dynamicRegistration": true
            },
            "callHierarchy": {
                "dynamicRegistration": true
            },
            "linkedEditingRange": {
                "dynamicRegistration": true
            },
            "semanticTokens": {
                "dynamicRegistration": true,
                "tokenTypes": [
                    "namespace",
                    "type",
                    "class",
                    "enum",
                    "interface",
                    "struct",
                    "typeParameter",
                    "parameter",
                    "variable",
                    "property",
                    "enumMember",
                    "event",
                    "function",
                    "method",
                    "macro",
                    "keyword",
                    "modifier",
                    "comment",
                    "string",
                    "number",
                    "regexp",
                    "decorator",
                    "operator"
                ],
                "tokenModifiers": [
                    "declaration",
                    "definition",
                    "readonly",
                    "static",
                    "deprecated",
                    "abstract",
                    "async",
                    "modification",
                    "documentation",
                    "defaultLibrary"
                ],
                "formats": [
                    "relative"
                ],
                "requests": {
                    "range": true,
                    "full": {
                        "delta": true
                    }
                },
                "multilineTokenSupport": false,
                "overlappingTokenSupport": false,
                "serverCancelSupport": true,
                "augmentsSyntaxTokens": true
            },
            "inlayHint": {
                "dynamicRegistration": true,
                "resolveSupport": {
                    "properties": [
                        "tooltip",
                        "textEdits",
                        "label.tooltip",
                        "label.location",
                        "label.command"
                    ]
                }
            },
            "inlineValue": {
                "dynamicRegistration": true
            },
            "diagnostic": {
                "dynamicRegistration": true,
                "relatedDocumentSupport": true
            },
            "typeHierarchy": {
                "dynamicRegistration": true
            }
        },
        "window": {
            "showMessage": {
                "messageActionItem": {
                    "additionalPropertiesSupport": true
                }
            },
            "showDocument": {
                "support": true
            },
            "workDoneProgress": true
        },
        "general": {
            "regularExpressions": {
                "engine": "ECMAScript",
                "version": "ES2020"
            },
            "markdown": {
                "parser": "marked",
                "version": "4.0.10"
            },
            "positionEncodings": [
                "utf-16"
            ],
            "staleRequestSupport": {
                "cancel": true,
                "retryOnContentModified": [
                    "textDocument/inlayHint",
                    "textDocument/semanticTokens/full",
                    "textDocument/semanticTokens/range",
                    "textDocument/semanticTokens/full/delta"
                ]
            }
        }
    },
    "initializationOptions": {},
    "trace": "verbose",
    "workspaceFolders": [
        {
            "uri": "file:///home/sify/Downloads",
            "name": "Downloads"
        }
    ],
    "locale": "en_US",
    "clientInfo": {
        "name": "coc.nvim",
        "version": "0.0.82"
    }
}

[Trace - 10:09:46.429] Received response 'initialize - (0)' in 604ms.
Result: {
    "capabilities": {
        "completionProvider": {
            "resolveProvider": false,
            "triggerCharacters": [
                "."
            ]
        },
        "definitionProvider": true,
        "referencesProvider": true,
        "hoverProvider": true,
        "textDocumentSync": 1,
        "workspace": {
            "workspaceFolders": {
                "supported": true
            }
        }
    }
}

[Trace - 10:09:46.430] Sending notification 'initialized'.
Params: {}

[Trace - 10:09:46.430] Received notification 'window/logMessage'.
Params: {
    "type": 1,
    "message": "An error has occurred initialising the compiler selected remote, please check your settings, reverting to the embedded compiler. Error: There was an error loading the remote version: latest,TypeError [ERR_INVALID_ARG_TYPE]: The \"path\" argument must be of type string. Received an instance of Object"
}

[Error - 10:09:46.430] An error has occurred initialising the compiler selected remote, please check your settings, reverting to the embedded compiler. Error: There was an error loading the remote version: latest,TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Object
[Trace - 10:09:46.432] Sending notification 'workspace/didChangeConfiguration'.
Params: {
    "settings": {
        "solidity": {
            "packageDefaultDependenciesContractsDirectory": "src",
            "packageDefaultDependenciesDirectory": "lib",
            "formatter": "forge"
        },
        "[solidity]": {
            "editor.defaultFormatter": "JuanBlanco.solidity"
        }
    }
}

[Trace - 10:09:46.432] Sending notification 'textDocument/didOpen'.
Params: {
    "textDocument": {
        "uri": "file:///home/sify/Downloads/Counter.sol",
        "languageId": "solidity",
        "version": 1,
        "text": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.13;\n\ncontract Counter {\n    uint256 public number;\n\n    function setNumber(uint256 newNumber) public {\n        number = newNumber;\n        address payable a = payable(msg.sender);\n    }\n\n    function increment() public {\n        number++;\n    }\n}\n"
    }
}

[Trace - 10:09:46.433] Received request 'client/registerCapability - (0)'.
Params: {
    "registrations": [
        {
            "id": "60aeacf8-4c56-4f6a-af6b-52f676f7273b",
            "method": "workspace/didChangeWorkspaceFolders",
            "registerOptions": {}
        }
    ]
}

[Trace - 10:09:46.433] Sending response 'client/registerCapability - (0)'. Processing request took 0ms
No result returned.

[Trace - 10:09:46.434] Received notification 'window/logMessage'.
Params: {
    "type": 1,
    "message": "An error has occurred initialising the compiler selected remote, please check your settings, reverting to the embedded compiler. Error: There was an error loading the remote version: latest,TypeError [ERR_INVALID_ARG_TYPE]: The \"path\" argument must be of type string. Received an instance of Object"
}

[Error - 10:09:46.434] An error has occurred initialising the compiler selected remote, please check your settings, reverting to the embedded compiler. Error: There was an error loading the remote version: latest,TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Object
[Trace - 10:09:48.049] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///home/sify/Downloads/Counter.sol",
    "diagnostics": [
        {
            "message": "Unused local variable.",
            "code": "2072",
            "range": {
                "end": {
                    "character": 25,
                    "line": 8
                },
                "start": {
                    "character": 8,
                    "line": 8
                }
            },
            "severity": 2
        }
    ]
}
fannheyward commented 8 months ago

Trigger :Format first and then check the trace logs. This logs didn't find formatting request.

fannheyward commented 8 months ago
[Trace - 10:09:46.429] Received response 'initialize - (0)' in 604ms.
Result: {
    "capabilities": {
        "completionProvider": {
            "resolveProvider": false,
            "triggerCharacters": [
                "."
            ]
        },
        "definitionProvider": true,
        "referencesProvider": true,
        "hoverProvider": true,
        "textDocumentSync": 1,
        "workspace": {
            "workspaceFolders": {
                "supported": true
            }
        }
    }
}

The language server didn't provide documentFormattingProvider, didn't support formatting.

sify21 commented 8 months ago

True, vscode-solidity relies on Prettier or Forge to do the formatting work.