-
Notifications
You must be signed in to change notification settings - Fork 37
Generic Handler and Easier Future Protocol Extensions #43
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
Draft
tris203
wants to merge
51
commits into
tliron:main
Choose a base branch
from
tris203:factory2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…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.
Collaborator
Author
|
@tliron when you have a moment, could you enable actions for the repo? |
…thod handler test
… and file to handler_translation.go
- 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…om method registration
…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`.
… request/notification handlers**
…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.
…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.
Collaborator
Author
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Supersedes #42
Essentially a complete rewrite of the handler side to use a generic handler
I accept this is probably almost unreviewable