ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
23.28k stars 5.77k forks source link

LSP Code Folding - Improper folding #12649

Closed stevennevins closed 1 year ago

stevennevins commented 2 years ago

Description

LSP improper detection of code folding

Environment

Steps to Reproduce

Example

setup function folds improperly


// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "ds-test/test.sol";

import "../../Greeter.sol";
import "forge-std/Vm.sol";

contract User {
    Greeter internal greeter;

    constructor(address _greeter) {
        greeter = Greeter(_greeter);
    }

    function greet(string memory greeting) public {
        greeter.greet(greeting);
    }

    function gm() public {
        greeter.gm();
    }
}

abstract contract Fixture1 is DSTest {
    Vm internal constant hevm = Vm(HEVM_ADDRESS);

    // contracts
    Greeter internal greeter;

    // users
    User internal alice;
    User internal bob;

    function setUp(
        address here,
        uint256 amount,
        address who,
        uint256 wad,
        uint256 test
    ) public virtual {
        greeter = new Greeter();
        alice = new User(address(greeter));
        bob = new User(address(greeter));
        greeter.transferOwnership(address(alice));
    }
}
Screen Shot 2022-02-08 at 9 40 27 AM
chriseth commented 2 years ago

Code folding is not implemented in the solidity lsp. Could this maybe come from a different plugin?

stevennevins commented 2 years ago

I think i read in the coc plugin docs that it consults the lsp to fold based on syntax. I'll do a bit more research and report back

stevennevins commented 2 years ago

I think this behavior is caused coc trying to handle the code folding itself and this is just coc doing it's best to infer folding ranges without knowing solidity syntax since it's not handled by the lsp. Might be more appropriate to close this issue and add this to the list prioritizing features to support

christianparpart commented 2 years ago

I actually had a look at how LSP can guide folding and it's actually not that complex: => https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_foldingRange

Also, coc.nvim does support that, so it should be fairly trivial to ensure functionality with some working clients.

github-actions[bot] commented 1 year ago

This issue has been marked as stale due to inactivity for the last 90 days. It will be automatically closed in 7 days.