Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Package name suggestion contains bad characters #796

Closed
frozzare opened this issue Feb 14, 2017 · 7 comments
Closed

Package name suggestion contains bad characters #796

frozzare opened this issue Feb 14, 2017 · 7 comments

Comments

@frozzare
Copy link

The suggested package name is built up on the directory name, but if the directory name contains a prefix, e.g go- the suggested package name will be go-mypack and that isn't allowed as a package name and it's not just a dash that don't work in a package name, e.g dot will not work either.

I don't have a good solution how to fix this since you don't want to confuse the user, but maybe some option that a user can configure what to strip from the suggested package name?

@ramya-rao-a
Copy link
Contributor

See #647 (comment) where I have put my thoughts on the subject.

That particular issue was closed as I added a solution for packages from gopkg.in as they specifically start wit "gopkg.in" end in ".v1" or v2 etc.

I think the best solution would be to update gopkgs tool to return both package name and the import path instead of just the import path. Then the Go extension can use the right package name instead of deducing it from the directory name.

Logged tpng/gopkgs#5 for the same.

Perhaps, you can give it a try?

@ramya-rao-a
Copy link
Contributor

As suggested tpng/gopkgs#5 (comment), it would be an overkill to implement this in gopkgs, but I have an idea at the moment I am exploring.

The output of gopkgs is currently cached and then used by the auto-complete feature. The cache only gets revised on a window reload. The cache has a mapping of import path to package name as deduced from the import path.

We can run go list separately and whenever it finishes, we can update the cache with the right package name.

So net result is that, may be for a few seconds of initial coding, you will see the directory name as package name, and after a while (how much ever time go list takes), you will start getting the right results. This way, user is not blocked by the slowness of go list.

cc @AlekSi including you here, as you first raised this issue.

@frozzare
Copy link
Author

frozzare commented Feb 15, 2017

It's sound like a good solution to use go list in the background and update the cache but what about new packages that don't will be listed with go list?

When I create a new package I don't have any go files and when I create my first go file mypack.go the suggested name will still be go-mypack since go list can't find mypack or am I wrong there?

@ramya-rao-a
Copy link
Contributor

Looks like I went off on a different tangent...

@frozzare you are talking about the specific case when user types package and auto-complete suggesting the directory name as package name

Whereas the issue I linked is about the when you try to use an existing package (but unimported) which maybe in a folder my-pack but could be named anything, in that case, you type "my" anywhere in your code, and the auto-complete suggests "my-pack" and this is not valid.

You are right, new packages will not show up in go list

For your case, we can use regex to check if the directory name is a valid package name. If yes, then we suggest it, if not then we don't suggest anything at all.

Thoughts?

@frozzare
Copy link
Author

Yeah that would work since it's better to suggest package name that actually are valid than package names that isn't valid :)

ramya-rao-a added a commit to ramya-rao-a/vscode-go that referenced this issue Feb 15, 2017
@ramya-rao-a
Copy link
Contributor

@frozzare With @uudashr's work in #1220 the packages whose names have - or . will get appropriate suggestions as well.

@frozzare
Copy link
Author

@ramya-rao-a sweet 👍

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants