Skip to content

x/tools/gopls: add go:embed support #50262

Closed
@hamidfzm

Description

@hamidfzm

Is your feature request related to a problem? Please describe.
Go embed feature introduced in version 1.16. Currently, go-vscode treats text like //go:embed app as a simple comment.

Describe the solution you'd like
Provide text highlighting or navigation by CTRL+Clicking on these comments

Describe alternatives you've considered
Goland provides this feature in its recent versions:
Screenshot from 2021-12-10 18-21-42

Additional context
VS code view
Screenshot from 2021-12-10 18-25-51

It would be really nice if we have this feature in my favorite code editor.

Activity

findleyr

findleyr commented on Dec 19, 2021

@findleyr
Member

This could be implemented with a code action+associated command that invokes window/showDocument. It could also be implemented with jump-to-definition+hover. I am not sure which is best, but this seems to belong in the gopls issue tracker.

transferred this issue fromgolang/vscode-goon Dec 19, 2021
changed the title [-]Add go:embed support[/-] [+]x/tools/gopls: add go:embed support[/+] on Dec 19, 2021
added
ToolsThis label describes issues relating to any tools in the x/tools repository.
goplsIssues related to the Go language server, gopls.
on Dec 19, 2021
added this to the Unreleased milestone on Dec 19, 2021
added
FeatureRequestIssues asking for a new feature that does not need a proposal.
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Dec 19, 2021
hyangah

hyangah commented on Jan 26, 2022

@hyangah
Contributor

For individual files, code action associated with window/showDocument or textDocument/documentLink would work. We still need a solution for handling folder type resources. For VSCode, I filed an issue microsoft/vscode#141564.

self-assigned this
on Apr 11, 2022
ansaba

ansaba commented on May 11, 2022

@ansaba

List of improvements

  • checks for the "embed" import
    Report it as semantic for highlighting
    The directive must immediately precede a line containing the declaration of a single variable. Only blank lines and ‘//’ line comments are permitted between the directive and the declaration.

EDIT (rfindley): cross out semantic highlighting, as I think we should punt on that for now

findleyr

findleyr commented on May 18, 2022

@findleyr
Member

We should also include a quick-fix to add the missing "embed" import.

23 remaining items

vikblom

vikblom commented on Jul 31, 2023

@vikblom

Hi @findleyr, is there a path forward with semantic highlighting here, given that the vscode ticket was closed by triage?

I tried out a naive textDocument/documentLink solution passing file:// URIs. Emacs could handle both files and directories. VSCode only accepted files. Does it makes sense to use that as a opt-in or base case (only files) feature?

You mentioned code action+associated command and jump-to-definition+hover above, which seems doable. However if VSCode requires specific (or new) mechanisms to handle directories, this feature might spread to codebases (vscode or vscode-go) I'm not familiar with

findleyr

findleyr commented on Sep 8, 2023

@findleyr
Member

Hi @vikblom, very sorry for the slow response on this.

Let's not worry about semantic tokens for now, I think that's a low priority. We can treat highlighting //go: directives as a separate project.

We discussed this in our triage meeting, and I think jump-to-definition+hover is the best way to implement this feature, as it will be supported by the greatest number of LSP clients. For directories, perhaps we should just pick an arbitrary file in the directory?

vikblom

vikblom commented on Sep 8, 2023

@vikblom

An arbitrary file could be unexpected as a user. But I don't see any alternatives if this is a limitation of LSP clients. I agree it is a good place to start.

I'll try to put something together and post a CL.

findleyr

findleyr commented on Sep 8, 2023

@findleyr
Member

Great, thanks for sticking to this!

gopherbot

gopherbot commented on Sep 21, 2023

@gopherbot
Contributor

Change https://go.dev/cl/530195 mentions this issue: gopls/internal/lsp: hover over embed directives.

gopherbot

gopherbot commented on Sep 29, 2023

@gopherbot
Contributor

Change https://go.dev/cl/531775 mentions this issue: gopls/internal/lsp: go to definition from embed directive

vikblom

vikblom commented on Oct 10, 2023

@vikblom

Hi @findleyr, what do you think is the next step? Would tackling semantic highlighting make sense?

findleyr

findleyr commented on Oct 10, 2023

@findleyr
Member

@vikblom if we're going to highlight go:embed, I think we should highlight all go: directives. Is that something you'd be interested in?

If so, I think we should perhaps make that a separate issue, and close this one.

vikblom

vikblom commented on Oct 10, 2023

@vikblom

Sure, I'd be glad to take a look directive highlights!

Thanks again for all the help in this issue.

findleyr

findleyr commented on Oct 13, 2023

@findleyr
Member

Great! Opened https://go.dev/issue/63538.

Will close this then.

locked and limited conversation to collaborators on Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FeatureRequestIssues asking for a new feature that does not need a proposal.FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/analysisIssues related to running analysis in goplshelp wanted

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @ansaba@hyangah@hamidfzm@gopherbot@vikblom

      Issue actions

        x/tools/gopls: add go:embed support · Issue #50262 · golang/go