roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

No local name suggestions in top-level code

Open just-ero opened this issue 6 months ago • 3 comments

Version

VS Code: 1.101.0 C# Extension: 2.82.12

Steps to reproduce

  1. Open a new console project with a top-level Program.cs file.
  2. Add a new local using a custom type, such as List<Person>
  3. Observe not getting a suggestion.

Expected Behavior

people is suggested for the local of type List<Person>.

This is the behavior in other contexts, such as in a simple void M() { } local function in the top-level code.

Actual Behavior

Nothing is suggested.

just-ero avatar Jun 16 '25 17:06 just-ero

Probably will need more info here - this appears to work for me: Image

  1. If you have an exact replica project you can share I can try that.
  2. Capture C# logs and C# LSP trace logs so we can see what the server is actually doing - https://github.com/dotnet/vscode-csharp/blob/main/SUPPORT.md#c-lsp-trace-logs

dibarbet avatar Jun 17 '25 22:06 dibarbet

@dibarbet The issue appears to happen only for custom types. For example, add a Person type to the project (can just be class Person; in the top-level file). Then add a List<Person> local. IntelliSense should suggest people here, like it does in other contexts. Seems to be a Roslyn issue instead?

The repro is simply this:

// Does not suggest anything.
// List<Person>

void M()
{
    // Suggests `people`.
    // List<Person>
}

class Person;

C# LSP Trace Logs
[Trace - 8:59:23 AM] Sending notification 'textDocument/didChange'.
Params: {
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs",
        "version": 7
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 12
                },
                "end": {
                    "line": 0,
                    "character": 12
                }
            },
            "rangeLength": 0,
            "text": " "
        }
    ]
}


[Trace - 8:59:23 AM] Sending request 'textDocument/diagnostic - (213)'.
Params: {
    "identifier": "HotReloadDiagnostics",
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    }
}


[Trace - 8:59:23 AM] Sending request 'textDocument/diagnostic - (214)'.
Params: {
    "identifier": "syntax",
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    },
    "previousResultId": "PublicDocumentPullDiagnosticsHandler(category: syntax):4"
}


[Trace - 8:59:23 AM] Sending request 'textDocument/diagnostic - (215)'.
Params: {
    "identifier": "XamlDiagnostics",
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    }
}


[Trace - 8:59:23 AM] Sending request 'textDocument/diagnostic - (216)'.
Params: {
    "identifier": "DocumentCompilerSemantic",
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    },
    "previousResultId": "PublicDocumentPullDiagnosticsHandler(category: DocumentCompilerSemantic):3"
}


[Trace - 8:59:23 AM] Sending request 'textDocument/diagnostic - (217)'.
Params: {
    "identifier": "DocumentAnalyzerSyntax",
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    },
    "previousResultId": "PublicDocumentPullDiagnosticsHandler(category: DocumentAnalyzerSyntax):7"
}


[Trace - 8:59:23 AM] Sending request 'textDocument/diagnostic - (218)'.
Params: {
    "identifier": "enc",
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    },
    "previousResultId": "PublicDocumentPullDiagnosticsHandler(category: enc):3"
}


[Trace - 8:59:23 AM] Sending request 'textDocument/diagnostic - (219)'.
Params: {
    "identifier": "DocumentAnalyzerSemantic",
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    },
    "previousResultId": "PublicDocumentPullDiagnosticsHandler(category: DocumentAnalyzerSemantic):3"
}


[Trace - 8:59:23 AM] Sending request 'textDocument/diagnostic - (220)'.
Params: {
    "identifier": "NonLocal",
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    }
}


[Trace - 8:59:23 AM] Sending request 'textDocument/diagnostic - (221)'.
Params: {
    "identifier": "WorkspaceDocumentsAndProject",
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    }
}


[Trace - 8:59:23 AM] Sending request 'textDocument/completion - (222)'.
Params: {
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    },
    "position": {
        "line": 0,
        "character": 13
    },
    "context": {
        "triggerKind": 2,
        "triggerCharacter": " "
    }
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/didChange] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/didChange] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] PublicDocumentPullDiagnosticsHandler(category: HotReloadDiagnostics) started getting diagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] previousResults.Length=0"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Processing 0 documents"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] PublicDocumentPullDiagnosticsHandler(category: syntax) started getting diagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public.PublicDocumentPullDiagnosticsHandler finished getting diagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] previousResults.Length=1"
}


[Trace - 8:59:23 AM] Received response 'textDocument/diagnostic - (213)' in 5ms.
No result returned.


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Processing 1 documents"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] PublicDocumentPullDiagnosticsHandler(category: XamlDiagnostics) started getting diagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] previousResults.Length=0"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Processing 0 documents"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public.PublicDocumentPullDiagnosticsHandler finished getting diagnostics"
}


[Trace - 8:59:23 AM] Received response 'textDocument/diagnostic - (215)' in 8ms.
No result returned.


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] PublicDocumentPullDiagnosticsHandler(category: DocumentCompilerSemantic) started getting diagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] previousResults.Length=1"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Processing 1 documents"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] PublicDocumentPullDiagnosticsHandler(category: DocumentAnalyzerSyntax) started getting diagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] previousResults.Length=1"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Processing 1 documents"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] PublicDocumentPullDiagnosticsHandler(category: enc) started getting diagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] previousResults.Length=1"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Processing 1 documents"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Found 0 diagnostics for OpenDocumentSource: D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs in 014-TopLevelLocalNameSuggestionRepro"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Diagnostics were unchanged for OpenDocumentSource: D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs in 014-TopLevelLocalNameSuggestionRepro"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public.PublicDocumentPullDiagnosticsHandler finished getting diagnostics"
}


[Trace - 8:59:23 AM] Received response 'textDocument/diagnostic - (218)' in 13ms.
Result: {
    "kind": "unchanged",
    "resultId": "PublicDocumentPullDiagnosticsHandler(category: enc):3"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] PublicDocumentPullDiagnosticsHandler(category: DocumentAnalyzerSemantic) started getting diagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] previousResults.Length=1"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Processing 1 documents"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] PublicDocumentPullDiagnosticsHandler(category: NonLocal) started getting diagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] previousResults.Length=0"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Processing 0 documents"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public.PublicDocumentPullDiagnosticsHandler finished getting diagnostics"
}


[Trace - 8:59:23 AM] Received response 'textDocument/diagnostic - (220)' in 16ms.
No result returned.


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Found 3 diagnostics for DocumentDiagnosticSource: D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs in 014-TopLevelLocalNameSuggestionRepro"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Diagnostics were unchanged for DocumentDiagnosticSource: D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs in 014-TopLevelLocalNameSuggestionRepro"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public.PublicDocumentPullDiagnosticsHandler finished getting diagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] PublicDocumentPullDiagnosticsHandler(category: WorkspaceDocumentsAndProject) started getting diagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] previousResults.Length=0"
}


[Trace - 8:59:23 AM] Received response 'textDocument/diagnostic - (214)' in 18ms.
Result: {
    "kind": "unchanged",
    "resultId": "PublicDocumentPullDiagnosticsHandler(category: syntax):4"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Processing 0 documents"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public.PublicDocumentPullDiagnosticsHandler finished getting diagnostics"
}


[Trace - 8:59:23 AM] Received response 'textDocument/diagnostic - (221)' in 19ms.
No result returned.


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/completion] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/completion] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Found 3 diagnostics for DocumentDiagnosticSource: D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs in 014-TopLevelLocalNameSuggestionRepro"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Diagnostics were unchanged for DocumentDiagnosticSource: D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs in 014-TopLevelLocalNameSuggestionRepro"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public.PublicDocumentPullDiagnosticsHandler finished getting diagnostics"
}


[Trace - 8:59:23 AM] Received response 'textDocument/diagnostic - (216)' in 20ms.
Result: {
    "kind": "unchanged",
    "resultId": "PublicDocumentPullDiagnosticsHandler(category: DocumentCompilerSemantic):3"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received response 'textDocument/completion - (222)' in 20ms.
No result returned.


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/completion] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[workspace/diagnostic] [LSP] Closing workspace/diagnostics request for enc"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[workspace/diagnostic] [LSP] Closing workspace/diagnostics request for WorkspaceDocumentsAndProject"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[workspace/diagnostic] [LSP] Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public.PublicWorkspacePullDiagnosticsHandler finished getting diagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[workspace/diagnostic] [LSP] Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public.PublicWorkspacePullDiagnosticsHandler finished getting diagnostics"
}


[Trace - 8:59:23 AM] Received response 'workspace/diagnostic - (212)' in 2874ms.
Result: {
    "items": []
}


[Trace - 8:59:23 AM] Received response 'workspace/diagnostic - (211)' in 2874ms.
Result: {
    "items": []
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[workspace/diagnostic] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[workspace/diagnostic] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Found 5 diagnostics for DocumentDiagnosticSource: D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs in 014-TopLevelLocalNameSuggestionRepro"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public.PublicDocumentPullDiagnosticsHandler finished getting diagnostics"
}


[Trace - 8:59:23 AM] Received response 'textDocument/diagnostic - (217)' in 23ms.
Result: {
    "kind": "full",
    "resultId": "PublicDocumentPullDiagnosticsHandler(category: DocumentAnalyzerSyntax):8",
    "items": []
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Found 0 diagnostics for DocumentDiagnosticSource: D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs in 014-TopLevelLocalNameSuggestionRepro"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Diagnostics were unchanged for DocumentDiagnosticSource: D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs in 014-TopLevelLocalNameSuggestionRepro"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public.PublicDocumentPullDiagnosticsHandler finished getting diagnostics"
}


[Trace - 8:59:23 AM] Received response 'textDocument/diagnostic - (219)' in 24ms.
Result: {
    "kind": "unchanged",
    "resultId": "PublicDocumentPullDiagnosticsHandler(category: DocumentAnalyzerSemantic):3"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/diagnostic] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Sending request 'textDocument/inlayHint - (223)'.
Params: {
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    },
    "range": {
        "start": {
            "line": 0,
            "character": 0
        },
        "end": {
            "line": 8,
            "character": 0
        }
    }
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/inlayHint] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/inlayHint] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received response 'textDocument/inlayHint - (223)' in 1ms.
Result: []


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/inlayHint] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[workspace/diagnostic] [LSP] Closing workspace/diagnostics request for HotReloadDiagnostics"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[workspace/diagnostic] [LSP] Microsoft.CodeAnalysis.LanguageServer.Handler.Diagnostics.Public.PublicWorkspacePullDiagnosticsHandler finished getting diagnostics"
}


[Trace - 8:59:23 AM] Received response 'workspace/diagnostic - (210)' in 2976ms.
Result: {
    "items": []
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[workspace/diagnostic] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Sending request 'textDocument/semanticTokens/range - (224)'.
Params: {
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    },
    "range": {
        "start": {
            "line": 0,
            "character": 0
        },
        "end": {
            "line": 8,
            "character": 0
        }
    }
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/semanticTokens/range] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/semanticTokens/range] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received response 'textDocument/semanticTokens/range - (224)' in 3ms.
Result: {
    "data": [
        0,
        0,
        4,
        2,
        0,
        0,
        4,
        1,
        21,
        0,
        0,
        1,
        6,
        2,
        0,
        0,
        6,
        1,
        21,
        0,
        2,
        0,
        4,
        15,
        0,
        0,
        5,
        1,
        8,
        0,
        0,
        1,
        1,
        44,
        0,
        0,
        1,
        1,
        44,
        0,
        1,
        0,
        1,
        44,
        0,
        1,
        4,
        15,
        17,
        0,
        1,
        0,
        1,
        44,
        0,
        2,
        0,
        5,
        15,
        0,
        0,
        6,
        6,
        2,
        0,
        0,
        6,
        1,
        44,
        0
    ]
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/semanticTokens/range] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Sending request 'textDocument/foldingRange - (225)'.
Params: {
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    }
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/foldingRange] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/foldingRange] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received response 'textDocument/foldingRange - (225)' in 2ms.
Result: []


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/foldingRange] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Sending request 'textDocument/codeLens - (226)'.
Params: {
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    }
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/codeLens] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/codeLens] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received response 'textDocument/codeLens - (226)' in 1ms.
Result: [
    {
        "range": {
            "start": {
                "line": 7,
                "character": 6
            },
            "end": {
                "line": 7,
                "character": 12
            }
        },
        "data": {
            "SyntaxVersion": "2025-06-18T06:59:23.1054944Z-10060-0",
            "ListIndex": 0,
            "TextDocument": {
                "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
            }
        }
    }
]


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/codeLens] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Sending request 'textDocument/documentSymbol - (227)'.
Params: {
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    }
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/documentSymbol] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/documentSymbol] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received response 'textDocument/documentSymbol - (227)' in 1ms.
Result: [
    {
        "glyph": 7,
        "children": [],
        "name": "Person",
        "detail": "Person",
        "kind": 5,
        "range": {
            "start": {
                "line": 7,
                "character": 0
            },
            "end": {
                "line": 7,
                "character": 13
            }
        },
        "selectionRange": {
            "start": {
                "line": 7,
                "character": 6
            },
            "end": {
                "line": 7,
                "character": 12
            }
        }
    },
    {
        "glyph": 7,
        "children": [
            {
                "glyph": 51,
                "children": [],
                "name": "<top-level-statements-entry-point>",
                "detail": "<top-level-statements-entry-point>",
                "kind": 6,
                "range": {
                    "start": {
                        "line": 0,
                        "character": 0
                    },
                    "end": {
                        "line": 8,
                        "character": 0
                    }
                },
                "selectionRange": {
                    "start": {
                        "line": 0,
                        "character": 0
                    },
                    "end": {
                        "line": 8,
                        "character": 0
                    }
                }
            }
        ],
        "name": "Program",
        "detail": "Program",
        "kind": 5,
        "range": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 8,
                "character": 0
            }
        },
        "selectionRange": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 0,
                "character": 4
            }
        }
    }
]


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/documentSymbol] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Sending request 'textDocument/documentSymbol - (228)'.
Params: {
    "textDocument": {
        "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
    }
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/documentSymbol] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/documentSymbol] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received response 'textDocument/documentSymbol - (228)' in 1ms.
Result: [
    {
        "glyph": 7,
        "children": [],
        "name": "Person",
        "detail": "Person",
        "kind": 5,
        "range": {
            "start": {
                "line": 7,
                "character": 0
            },
            "end": {
                "line": 7,
                "character": 13
            }
        },
        "selectionRange": {
            "start": {
                "line": 7,
                "character": 6
            },
            "end": {
                "line": 7,
                "character": 12
            }
        }
    },
    {
        "glyph": 7,
        "children": [
            {
                "glyph": 51,
                "children": [],
                "name": "<top-level-statements-entry-point>",
                "detail": "<top-level-statements-entry-point>",
                "kind": 6,
                "range": {
                    "start": {
                        "line": 0,
                        "character": 0
                    },
                    "end": {
                        "line": 8,
                        "character": 0
                    }
                },
                "selectionRange": {
                    "start": {
                        "line": 0,
                        "character": 0
                    },
                    "end": {
                        "line": 8,
                        "character": 0
                    }
                }
            }
        ],
        "name": "Program",
        "detail": "Program",
        "kind": 5,
        "range": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 8,
                "character": 0
            }
        },
        "selectionRange": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 0,
                "character": 4
            }
        }
    }
]


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[textDocument/documentSymbol] [LSP] Request handler completed successfully."
}


[Trace - 8:59:23 AM] Sending request 'codeLens/resolve - (229)'.
Params: {
    "range": {
        "start": {
            "line": 7,
            "character": 6
        },
        "end": {
            "line": 7,
            "character": 12
        }
    },
    "data": {
        "SyntaxVersion": "2025-06-18T06:59:23.1054944Z-10060-0",
        "ListIndex": 0,
        "TextDocument": {
            "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
        }
    }
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[codeLens/resolve] [LSP] D:\\Code\\Projects\\.temp\\cs\\014-TopLevelLocalNameSuggestionRepro\\Program.cs found in workspace Host"
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[codeLens/resolve] [LSP] Starting request handler"
}


[Trace - 8:59:23 AM] Received response 'codeLens/resolve - (229)' in 3ms.
Result: {
    "range": {
        "start": {
            "line": 7,
            "character": 6
        },
        "end": {
            "line": 7,
            "character": 12
        }
    },
    "command": {
        "title": "1 reference",
        "command": "roslyn.client.peekReferences",
        "arguments": [
            "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs",
            {
                "line": 7,
                "character": 6
            }
        ]
    },
    "data": {
        "SyntaxVersion": "2025-06-18T06:59:23.1054944Z-10060-0",
        "ListIndex": 0,
        "TextDocument": {
            "uri": "file:///d:/Code/Projects/.temp/cs/014-TopLevelLocalNameSuggestionRepro/Program.cs"
        }
    }
}


[Trace - 8:59:23 AM] Received notification 'window/logMessage'.
Params: {
    "type": 5,
    "message": "[codeLens/resolve] [LSP] Request handler completed successfully."
}

just-ero avatar Jun 18 '25 07:06 just-ero

@dibarbet The issue appears to happen only for custom types. For example, add a Person type to the project (can just be class Person; in the top-level file). Then add a List<Person> local. IntelliSense should suggest people here, like it does in other contexts. Seems to be a Roslyn issue instead?

Perfect, I can definitely reproduce that, and appears to be an issue in VS as well. Transferring over to roslyn

dibarbet avatar Jun 18 '25 07:06 dibarbet

took a quick look at the trees here. It looks like the syntax tree structure is very different for List<Person> in a top level declaration vs inside a normal method. It is even different comparing to List<int> in a top level declaration.

List<Person> in top level (fails)

With the following in Program.cs:

// Does not suggest anything.
List<Person>
class Person;

looks like it gets parsed as a GreaterThanExpression. When we try and get the symbol for this expression, it returns none. Image

List<int> in top level (works)

With the following in Program.cs:

// Does not suggest anything.
List<int>
class Person;

looks like it gets parsed as a GenericName and we can find the symbol for it. Image

In fact if you also don't define Person, it also appears to get parsed as a GenericName which also works.

List<Person> in a method (works)

void M()
{
    // Suggests `people`.
    List<Person>
}
class Person;

also parsed as part of a GenericName Image

The different trees here are making me think this should be fixed on the compiler side to better handle this case in a top level program. Moving over to @dotnet/roslyn-compiler , let me know if you think otherwise.

dibarbet avatar Jun 19 '25 21:06 dibarbet

This is by no means limited to TLS. Pretty much any generic declaration followed by anything that's not an identifier will have this shape. For example, inside a method followed by an if:

Image

The root of the issue is this line in the parser; if the next token is not an identifier, we assume that we cannot be in the middle of a local declaration. It feels like we could potentially make this a bit looser; maybe if the next token is any kind of keyword that starts a statement or block? For example, we can't assume this if the next token is await, as we could legitimately be parsing an expression of List < Person > await somethingElse, but if we see List<Person> if, or List<Person> class, or similar, it seems reasonable that we could assume that we're in error recovery and that we should assume this is a generic type name. @CyrusNajmabadi, do you have thoughts?

333fred avatar Jun 20 '25 23:06 333fred

Yes. We already have code in several places to make better choices about generic types vs expressions. Especially when code is in error, and there is a following line break. We can def do the same here.

Feel free to fix. Or assign to me and I can do when I have time.

CyrusNajmabadi avatar Jun 21 '25 00:06 CyrusNajmabadi