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

Statement on first line in top-level statements file is treated incorrectly when partial class Program definition is present #7762

Open
just-ero opened this issue Nov 9, 2024 · 4 comments
Labels

Comments

@just-ero
Copy link

just-ero commented Nov 9, 2024

Environment

VS Code version: 1.95.2, e8653663e8840adaf45af01eab5c627a5af81807, x64
C# Extension version: v2.55.21

Steps to reproduce

  1. Create or open any C# project.
  2. Open or create a top-level statements (Program.cs) file.
  3. Add the following code:
    int i;
    
    partial class Program;
  4. Observe int i; being treated incorrectly; it is "folded away":
    Image

Expected Behavior

The statement on the first line is not treated incorrectly like this.

Actual Behavior

The statement is in an extra "container", navigating to the line with the cursor hides the cursor behind that container. The contents of the line can still be edited. Clicking the container does not yield a response.

@just-ero
Copy link
Author

just-ero commented Nov 9, 2024

To add a use-case for a partial class Program definition in a top-level statements file: it allows for defining (partial) members that can be used in the top-level code:

// ...

partial class Program
{
    [GeneratedRegex(@"...")]
    private partial Regex MyRegex { get; }
}

@JoeRobich
Copy link
Member

JoeRobich commented Nov 14, 2024

documentSymbols response from the repro code.

[Trace - 3:43:50 PM] Received response 'textDocument/documentSymbol - (3888)' in 2ms.
Result: [
    {
        "glyph": 7,
        "children": [
            {
                "glyph": 51,
                "children": [],
                "name": "<Main>$",
                "detail": "<top-level-statements-entry-point>",
                "kind": 6,
                "range": {
                    "start": {
                        "line": 0,
                        "character": 0
                    },
                    "end": {
                        "line": 3,
                        "character": 0
                    }
                },
                "selectionRange": {
                    "start": {
                        "line": 0,
                        "character": 0
                    },
                    "end": {
                        "line": 3,
                        "character": 0
                    }
                }
            }
        ],
        "name": "Program",
        "detail": "Program",
        "kind": 5,
        "range": {
            "start": {
                "line": 2,
                "character": 0
            },
            "end": {
                "line": 2,
                "character": 22
            }
        },
        "selectionRange": {
            "start": {
                "line": 2,
                "character": 14
            },
            "end": {
                "line": 2,
                "character": 21
            }
        }
    }
]

Testing with a class name other than Program.

for example:

int i;

partial class Test;

The response is

[Trace - 3:55:28 PM] Received response 'textDocument/documentSymbol - (7764)' in 14ms.
Result: [
    {
        "glyph": 7,
        "children": [],
        "name": "Test",
        "detail": "Test",
        "kind": 5,
        "range": {
            "start": {
                "line": 2,
                "character": 0
            },
            "end": {
                "line": 2,
                "character": 19
            }
        },
        "selectionRange": {
            "start": {
                "line": 2,
                "character": 14
            },
            "end": {
                "line": 2,
                "character": 18
            }
        }
    }
]

Program being "special" brings along the <Main>$: <top-level-statements-entry-point> symbol which isn't entirely useful here even if it is correct.

On a tangential note, I can see how it would be nice to include local functions in the documentSymbols, especially for top-level statements.

@JoeRobich
Copy link
Member

Thinking about this more, the <Main>$: <top-level-statements-entry-point> symbol is correct. The problem here is the range of the Program symbol which should be the entire document.

@JoeRobich
Copy link
Member

Tested this in VS proper and there are no issues with Sticky Scroll. My hunch is that VS Code is using a combination of documentSymbol and foldingRange for their sticky scroll.

@JoeRobich JoeRobich added the Bug label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants