question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a custom request to open yaml file and select a given property key

See original GitHub issue

Is your enhancement related to a problem? Please describe.

vscode-microprofile depends vscode-yaml to manage completion, validation, hover, etc for application.yaml. To do that we generate a JSON Schema according to the Java project classpath.

In Quarkus/MicroProfile, we can declare a property foo.bar in Java file:

public class Test {

 @ConfigProperty(name = "foo.bar")
  private Integer test;
}

and we can configure this property with the application.yaml like this:

foo:
  bar: 10

I’m implementing go to the definition from the Java file to the properties file and yaml file. In other words, when cursor is inside the name of the annotation (see cursor at |);

@ConfigProperty(name = "foo|.bar")

I would like to open the application.yaml and select the bar property key even if application.yaml is not opened.

Describe the solution you would like

It should be nice if we could consume a custom service like selectPropertyKey("foo.bar") to open the application.yaml and select the property key.

Describe alternatives you have considered

I will try for the moment to open the application.yaml with standard LSP definition request by setting 0 as location.

Thanks for your help!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
angelozerrcommented, Nov 30, 2020

vscode-yaml on start may scan all installed extensions, look on “yaml-language-server-plugin” value, collect those paths and pass them to yaml-ls. Yaml-ls may load such files, but the main problem starts there.

I love that 😃

as we do not have API with such plugins may use.

I think you should follow the same API that we use for JDT LS and XML Language Server with IDelegateCommandHandler: https://github.com/eclipse/lemminx/blob/11f6f6df3ac2a7c574b399d6ef40a128b2cfd6a7/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/extensions/commands/IXMLCommandService.java#L33

The question is about context:

  • in Java you need to retrieve in your command a ICompilationUnit from an uri. JDT manages a static context kind to retrieve a ICompilationUnit from an URI.
  • in XML context you need to retrieve a DOM document from an uri. LemMinX provides this kind of feature by using the opened documents.

To avoid breaking the command API, I suggest this idea:

interface IDelegateCommandHandler {
		
		/**
		 * Executes a command
		 * @param params command execution parameters
		 * @param cancelChecker check if cancel has been requested
		 * @return the result of the command
		 * @throws Exception the unhandled exception will be wrapped in
		 *                   <code>org.eclipse.lsp4j.jsonrpc.ResponseErrorException</code>
		 *                   and be wired back to the JSON-RPC protocol caller
		 */
	    Object executeCommand(ExecuteCommandParams params, IYamlContext context, CancelChecker cancelChecker) throws Exception;	    
}

and YamlContext could provide methods like

  • YamlDocument getYamlDocument(string uri)
  • YamlDocument parseYaml(string content)

I think it can be a good start.

1reaction
evidolobcommented, Nov 30, 2020

@angelozerr I’m assuming that you implement go to the definition with vscode.DefinitionProvider in such case you provide vscode.Location object, which contains file URI and Range where some symbol defined. VSCode use that uri to open file and Range to place cursor.

I’m not sure why do you need to open YAML manually or using API from yaml extension. I can assume that you may need some sort of API to calculate where some property defined in yaml file, to build Range object.

Another good question, is how to pass path to yaml node, I think we can use yaml path or jsonpath

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to find specific property key in a yaml file using intellij idea?
It can be invoked by pressing shift key twice or by invoking search menu (by pressing ctrl + n ) and selecting 'all'...
Read more >
YAML Tutorial: Everything You Need to Get Started in Minutes
Let's take a look at a YAML file for a brief overview. ... stream = open("foo.yaml", 'r') dictionary = yaml.load(stream) for key, value...
Read more >
Customize your pipeline - Azure Pipelines - Microsoft Learn
A pipeline is defined using a YAML file in your repo. ... Navigate to the Pipelines page in Azure Pipelines, select the pipeline...
Read more >
YAML File As Configuration Property In Mule | Mulesoft Tutorials
YAML file to define property in hierarchical manner and consume the property from inside the dataweave or mule configuration.
Read more >
Create and Configure Jobs and Pipelines Using YAML
The name field in the configuration file defines the job's or pipeline's name. If no name is specified, the build system creates a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found