Skip to content

Extended Hover not working without modeline #1042

@arunvenmany-ibm

Description

@arunvenmany-ibm

Summary

Hi @msivasubramaniaan
We are trying to extend yaml-language-server and create a customized version of language server which provides schema based validations for some fields.
We are facing an issue related to YamlSchemaService, which fails to recognize the default schema that we passed through the client package json

Relevant information

In client, we passed a custom json, through yaml.schemas

"yaml.schemas": {
"type": "object",
"default": {
"<schema_path>":["*.yaml"]
},
"description": "Associate schemas to YAML files in the current workspace"
}`

We are trying to extend YamlServerInit class and provide the custom functionality to bind our own hover/completion/validation provider to language service

export class EasejYAMLServerInit extends YAMLServerInit {
constructor(
private customConnection: Connection,
private customYAMLSettings: SettingsState,
private customWorkspaceContext: WorkspaceContextService,
private customSchemaRequestService: SchemaRequestService,
private customTelemetry: Telemetry
) {
super(customConnection, customYAMLSettings, customWorkspaceContext, customSchemaRequestService, customTelemetry);
}

connectionInitialized(params: InitializeParams): InitializeResult {
const initializedResult = super.connectionInitialized(params);
const yamlSchemaService = new YAMLSchemaService(this.customSchemaRequestService, this.customWorkspaceContext);
const hover = new CustomYAMLHover(yamlSchemaService, this.customTelemetry);
hover.configure({hover:this.customYAMLSettings.yamlShouldHover,
indentation:this.customYAMLSettings.indentation})
this.languageService.doHover = hover.doHover.bind(hover);
new RequestHandlers(this.customConnection, this.languageService).registerHandlers();
return initializedResult;
}
}

Here the problem is that hover doesn't work without us adding "modeline" explicitly as the yamlSchemaService is unable to get the default schema set to settings

Screen.Recording.2025-03-21.at.4.16.28.PM.mov

As you can see, the schema is taken from client, but hover is not working.
But if I add the below line, hover works fine
#yaml-language-server: $schema=<path_to_my_schema>

I identified the problem is that we are unable to configure the YamlSchemaService when we initialize , whereas when its created inside LanguageService, configure() method takes care of adding the settings from SettingsProvider.

Image

We would like to achieve similar functionality of configure() method in LanguageService, but not sure how to get the settings inside YamlServerInit

We manually added a line hardcoding schema after new YamlSchemaService() in our code
yamlSchemaService.registerExternalSchema('<path_to_schema>', ['*.yaml'])

This resolves the hover problem, but we cannot hardcode the schema in both client and server. It should be accessible via settings.

Similarly, we have requirements to add more settings to be configured via client. This would require either we fully rewrite the settingshandler or we need methods to get and set custom settings

Proposed solution

It would be helpful if we can have a method in settings to retrieve the current languageSettings and another methods to get and set custom settings
Please help with the code changes or suggest another way to achieve this.

Metadata

Metadata

Type

No type

Projects

Status

📋 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions