Skip to content

Commit

Permalink
unsafe downcasts until service registry is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
montymxb committed Nov 17, 2023
1 parent 971641e commit d04fdf8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/langium/src/lsp/language-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,10 @@ export function createCallHierarchyRequestHandler<P extends CallHierarchyIncomin
};
}

export function addTypeHierarchyHandler(connection: Connection, sharedServices: LangiumSharedServices): void {
export function addTypeHierarchyHandler(connection: Connection, sharedServices: LangiumSharedServices & LangiumSharedLSPServices): void {
// Don't register type hierarchy handlers if no type hierarchy provider is registered
if (!sharedServices.ServiceRegistry.all.some(services => services.lsp.TypeHierarchyProvider)) {
// TODO @montymxb downcast is not safe, needs additional work
if (!sharedServices.ServiceRegistry.all.some(services => (services as LangiumCombinedServices).lsp.TypeHierarchyProvider)) {
return;
}

Expand All @@ -547,13 +548,15 @@ export function addTypeHierarchyHandler(connection: Connection, sharedServices:

connection.languages.typeHierarchy.onSupertypes(
createTypeHierarchyRequestHandler((services, params, cancelToken) => {
return services.lsp.TypeHierarchyProvider?.supertypes(params, cancelToken) ?? null;
// TODO @montymxb downcast is not safe, needs additional work
return (services as LangiumCombinedServices).lsp.TypeHierarchyProvider?.supertypes(params, cancelToken) ?? null;
}, sharedServices),
);

connection.languages.typeHierarchy.onSubtypes(
createTypeHierarchyRequestHandler((services, params, cancelToken) => {
return services.lsp.TypeHierarchyProvider?.subtypes(params, cancelToken) ?? null;
// TODO @montymxb downcast is not safe, needs additional work
return (services as LangiumCombinedServices).lsp.TypeHierarchyProvider?.subtypes(params, cancelToken) ?? null;
}, sharedServices),
);
}
Expand Down

0 comments on commit d04fdf8

Please sign in to comment.