Skip to content
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

Feat: Go to definition for uris in string content #23

Conversation

WilsonZiweiWang
Copy link
Contributor

This PR provides go to definition for uris prefixed with file:// in the string content. Example:
image

Caveat:
Since VSCode inherently handles the URIs in the string with ctrl + click to provide redirection. It is difficult to trigger go to definition with the same shortcut, the go to definition in the normal right-click context menu will still work.

const { workspaceFolders } = analyzer
if (workspaceFolders !== undefined && workspaceFolders !== null) {
for (const workspaceFolder of workspaceFolders) {
const filePath = findFileInDirectory(workspaceFolder.uri.replace('file://', ''), uriAtPosition.name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user's workspace may contain several yocto layers and build directories which are not ignored here. Looking up the whole workspaceFolder will be inaccurate and slow. I suggest rather searching only the directory or immediate parent of the recipe file.

@@ -132,3 +156,22 @@ function createDefinitionLocationForPathInfo (path: ParsedPath): Location {

return location
}

function findFileInDirectory (dir: string, fileName: string): string | null {
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a library for finding files, I don't think there is added value in defining this ourselves.
Use https://code.visualstudio.com/api/references/vscode-api#workspace.findFiles
(or alternatively https://github.com/isaacs/node-glob)

})
if (foundRecipe !== undefined) {
if (foundRecipe?.path !== undefined) {
allSymbolsAtPosition.push({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure there is a need for go to definition for URIs. They are usually related only to the current file itself. Why could several recipe files be matched? Only the opened one should be suggested I think.


SRC_URI = 'file://foo.inc \
file://foo.inc'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird for a bitbake file to provide the same URI twice. Not sure it would be compile through bitbake.

})
if (foundRecipe !== undefined) {
if (foundRecipe?.path !== undefined) {
allSymbolsAtPosition.push({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of providing "Go to definition", register a https://code.visualstudio.com/api/references/vscode-api#DocumentLinkProvider
This will make ctrl+click work instead of manually selecting "go to definition".

@WilsonZiweiWang WilsonZiweiWang marked this pull request as draft December 6, 2023 23:50
@WilsonZiweiWang
Copy link
Contributor Author

Opened a new PR using documentLinkProvider: #27

@deribaucourt
Copy link
Member

Duplicate of #27

@deribaucourt deribaucourt marked this as a duplicate of #27 Dec 11, 2023
@WilsonZiweiWang WilsonZiweiWang deleted the Feature-10430-go-to-definition-for-SRC-URI branch January 29, 2024 22:12
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.

2 participants