Skip to content

Conversation

@tris203
Copy link
Collaborator

@tris203 tris203 commented Jul 4, 2025

Supersedes #42

Essentially a complete rewrite of the handler side to use a generic handler

I accept this is probably almost unreviewable

tris203 added 14 commits June 29, 2025 22:39
…ensibility

- Move generic handler logic (HandlerFunc, HandlerInterface, factory functions) from protocol/316_handler.go to common.go for reuse.
- Update Handler_316 to provide a GetMethodMap method returning a map of methods to handler interfaces.
- Refactor server handler logic to use the new HandlerInterface and GetMethodMap, centralizing method dispatch in server/handler.go.
- Remove duplicated handler logic from protocol/316_handler.go.
- Prepare for future support of custom handlers.
…ate client capabilities types

- Move generic handler factory functions (NewNotificationHandler, NewTypedHandler, etc.) from root to protocol/translation/request_translation.go.
- Update all handler registrations in Handler_316 to use translation package factories.
- Refactor client capabilities types: rename ClientCapabilities and TextDocumentClientCapabilities to *_317 variants, update references and method receivers accordingly.
- Remove obsolete request_translation.go from root.
Refactored Handler_317 to replace the large switch statement in Handle with GetMethodMap and GetCustomMethods, which return maps of methods to handler interfaces. This simplifies method dispatch, improves maintainability, and leverages the translation package for handler construction.
Refactored all server-related methods to use 's' instead of 'self' as the receiver name, improving code consistency and readability. Updated related comments and variable references accordingly. No functional changes.
- Replaced usage of github.com/pkg/errors with fmt.Errorf and %w for error wrapping in server/run-websocket.go.
- Removed pkg/errors from go.mod and go.sum.
@tris203 tris203 changed the title wip Generic Handler and Easier Future Protocol Extensions Jul 4, 2025
@tris203 tris203 requested a review from Copilot July 4, 2025 19:11

This comment was marked as outdated.

@tris203
Copy link
Collaborator Author

tris203 commented Jul 4, 2025

@tliron when you have a moment, could you enable actions for the repo?

tris203 added 7 commits July 4, 2025 22:26
- Remove per-handler CustomMethod maps and handler structs from Handler_316 and Handler_317.
- Introduce global customMethods map and AddCustomRequest/AddCustomNotification functions for registering custom methods.
- Update handler translation to use more generic types for custom handlers.
… registration

Refactor protocol handler function types to use generic RequestFunc, NoticationFunc, and ContextOnlyFunc signatures. Remove legacy per-method handler types and update handler structs and registration logic accordingly. This change reduces boilerplate, improves type consistency, and simplifies adding new handlers.
@tris203 tris203 requested a review from Copilot July 5, 2025 21:20

This comment was marked as outdated.

tris203 and others added 11 commits July 5, 2025 23:37
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ucts

- Add `.github/workflows/generate.yml` to automate `go generate` and enforce generated code is committed.
- Introduce `gen_methodmap.go` code generator for handler method maps.
- Refactor `Handler_316` and `Handler_317` to embed new `common_handler` struct and use generated `GetMethodMap` methods.
- Add generated files `316_method_gen.go` and `317_method_gen.go` for handler method maps.
- Extract common handler fields to `common_handler.go`.
- Replace text/template-based code generation in gen_methodmap.go with github.com/dave/jennifer for programmatic Go code generation.
- Add github.com/dave/jennifer as a dependency in go.mod, go.sum, and tools/tools.go.
- Update generated *_method_gen.go files to use consistent field ordering and improved import aliasing.
…constants

- Renamed protocol version constants from `Protocol_3_16`, `Protocol_3_17`, `Protocol_3_18` to `Protocol_316`, `Protocol_317`, `Protocol_318` for consistency.
- Updated all references in code and tests to use new constant names.
- Moved `IsInitialized`, `SetInitialized`, and `GetVersion` methods for protocol handlers to generated code via `gen_methodmap.go`.
- Updated workflow to install Go dependencies before running `go generate`.
…neration

- Remove individual LSP method string constants from protocol files.
- Add new `methods_gen.go` (auto-generated) to define all LSP method names as Go constants, based on upstream LSP metaModel.
- Update handler structs and method maps to use new method constant names.
- Move and update method map generator to `tools/genmethodmap/main.go`.
- Add `tools/genprotocol/main.go` to generate method constants from LSP metaModel.
- Update go:generate directives and paths for new generator locations.
- Updated `tools/genprotocol/main.go` to extract and normalize the `since` version for each method and notification.
- Modified the generated `protocol/methods_gen.go` to include `@since <version>` comments for all LSP method constants, defaulting to `<3.16.0` when unspecified.
- Improved struct field ordering for consistency with the protocol meta-model.
tris203 added 11 commits July 11, 2025 08:08
…s.go

- Added //go:build tools tag to main.go files in genmethodmap and genprotocol to mark them as tool binaries.
- Removed tools/tools.go dummy package, consolidating build tags directly into tool entrypoints.
…eration

- Replace `ServerCapabilities_316` and `ServerCapabilities_317` with a single `ServerCapabilities` struct.
- Move shared types and helpers to new `base_types.go`.
- Add `capabilities.go` with a generic `CreateServerCapabilities` function using reflection to generate capabilities based on handler fields.
- Remove per-version capability generation methods from handler files.
- Update initialization and tests to use unified capabilities.
… refactor usage

- Introduce constants for handler names, capability field names, and file operation types in `capabilities.go`.
- Refactor all usages in `CreateServerCapabilities` and helper functions to use these constants instead of string literals.
- Add `capabilities_test.go` with unit tests for `CreateServerCapabilities` covering various handler scenarios.
…itle function

Replaces usage of the deprecated strings.Title with a new local Title function in generate.go. The new function preserves previous behavior for word capitalization and avoids reliance on deprecated standard library APIs.
…tilities

- Refactored `CreateServerCapabilities` to use reflection, reducing code duplication and supporting both Handler_316 and Handler_317 via generics.
- Introduced helper functions for setting capability fields, text document sync options, semantic tokens, and file operations.
- Added constants for handler and capability field names.
- Added comprehensive unit tests for server capabilities creation.
- Added new `trace.go` utility for managing and emitting trace messages with thread-safe trace level management.
…nstead of any

Refactor Handler_316 and Handler_317 to replace several RequestFunc response types from `any` to more specific types such as `[]CodeAction`, `CompletionList`, `[]Location`, `DocumentDiagnosticReport`, and others. This improves type safety and aligns handler signatures with LSP protocol expectations.
- Added handlers and method mappings for WorkspaceDiagnostic, InlineValue, InlayHint, InlayHintResolve, and WorkspaceSymbolResolve.
- Updated server capabilities to advertise support for WorkspaceDiagnostic, InlineValueProvider, InlayHintProvider, InlayHintResolveProvider, and WorkspaceSymbolResolveProvider.
Introduce `Handler_318` struct and generated method map for LSP 3.18 protocol support, including new handlers for inline completion and notebook document events. Update `capabilities.go` to register new handler names and capabilities (`InlineCompletionProvider`, `NotebookDocumentSync`), and extend the `Handlers` union and `CreateServerCapabilities` logic to support LSP 3.18 features.
@tris203
Copy link
Collaborator Author

tris203 commented Jul 15, 2025

I think this is ready as soon as we can get CI turned on for the repo

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.

1 participant