Skip to content

Fix infinite loop for token format#5

Merged
myleshyson merged 3 commits intomyleshyson:release/1.0.1from
rockerBOO:token-format-json
Jun 26, 2025
Merged

Fix infinite loop for token format#5
myleshyson merged 3 commits intomyleshyson:release/1.0.1from
rockerBOO:token-format-json

Conversation

@rockerBOO
Copy link
Copy Markdown
Contributor

@rockerBOO rockerBOO commented Jun 26, 2025

I am setting up ClientCapabilties like

		semanticTokens := protocol.SemanticTokensClientCapabilities{
			TokenTypes: []string{
				"namespace", "type", "class", "enum", "interface", "struct",
				"typeParameter", "parameter", "variable", "property", "enumMember",
				"event", "function", "method", "macro", "keyword", "modifier",
				"comment", "string", "number", "regexp", "operator",
			},

			TokenModifiers: []string{
				"declaration", "definition", "readonly", "static", "deprecated",
				"abstract", "async", "modification", "documentation", "defaultLibrary",
			},
			Formats:               []protocol.TokenFormat{protocol.TokenFormatRelative},
			DynamicRegistration:   false,
			MultilineTokenSupport: false,
			ServerCancelSupport:   false,
			AugmentsSyntaxTokens:  true,
		}

		params := protocol.InitializeParams{
			ProcessId: &process_id,
			ClientInfo: &protocol.ClientInfo{
				Name:    "MCP-LSP Bridge",
				Version: "1.0.0",
			},
			RootUri:          &root_uri,
			WorkspaceFolders: &workspaceFolders,
			Capabilities: protocol.ClientCapabilities{
				TextDocument: &protocol.TextDocumentClientCapabilities{
					SignatureHelp:  &protocol.SignatureHelpClientCapabilities{},
					SemanticTokens: &semanticTokens,
				},
			},
		}

but it causes it to loop infinitely when converting to JSON. Due to the protocol.TokenFormat.

This change converts the type into a string which prevents it from looping infinitely. I am not 100% sure if this is the best fix it but does fix it.

Thanks!

@myleshyson
Copy link
Copy Markdown
Owner

thanks for reporting! types.go is actually a generated file, so the change would have to be in python. Can you make that update in python? You'll need to make the change in enums.py

@myleshyson myleshyson self-assigned this Jun 26, 2025
@rockerBOO
Copy link
Copy Markdown
Contributor Author

rockerBOO commented Jun 26, 2025

I do not know how to run the generator to test but I have updated that part and reverted types.go

Edit: Oh I see from the workflow. So we'll need to figure out what the type is (uint32 or string) but it's a little more involved for me to figure out. Might take a little longer to get that in there.

@rockerBOO
Copy link
Copy Markdown
Contributor Author

Ok I think this works now. I am newer to Go though so let me know if there is some other tests we could add to test the JSON marshaling.

@myleshyson myleshyson changed the base branch from main to release/1.0.1 June 26, 2025 23:27
@myleshyson myleshyson merged commit 99c6798 into myleshyson:release/1.0.1 Jun 26, 2025
1 check passed
@myleshyson
Copy link
Copy Markdown
Owner

Ok this is merged in now and released at 1.0.1. Thanks again 👍

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

Successfully merging this pull request may close these issues.

2 participants