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

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

Closed
sify21 opened this issue Jan 23, 2024 · 5 comments
Closed

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

sify21 opened this issue Jan 23, 2024 · 5 comments

Comments

@sify21
Copy link

sify21 commented Jan 23, 2024

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

  • Create file mini.vim with:
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
  • Install vscode-solidity-server
    since it's not published to npm yet, you have to install it locally.
git clone git@github.com:juanfranblanco/vscode-solidity.git
cd  vscode-solidity
npm ci
npm run prepublishOnly
npm link
  • Configure coc-settings.json

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"
            }
        }
    }
}
  • Start (neo)vim with command: vim -u mini.vim

  • Open a solidity file like this one Counter.sol and run :Format

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

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
Copy link
Member

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

@sify21
Copy link
Author

sify21 commented Jan 24, 2024

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
Copy link
Member

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

@fannheyward
Copy link
Member

[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
Copy link
Author

sify21 commented Jan 24, 2024

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

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

No branches or pull requests

2 participants