Goland (version 2021.2, on Linux) can't auto import "fmt", when add a line of code that use fmt's functions.
I need to add import "fmt" by hand.
But seems it doesn't have problem with other built-in go packages.
It that a bug, or a special design ?
BTW, the similar issue occur for 3rd-party package "github.com/stretchr/testify/assert", the auto import will hint several options to import assert, but the above one is always not in the list in my case, had to import by hand.
Screenshot:
#Update: Cause of issue & solution found
Issue:
Solution: just remove the 2 line, then import works immediately.
Thanks to s0xzwasd's comment under question, and jinseok.oh's answer, which actually mentioned the setting.
There is Global Println() function and also fmt.Println() function()
If you writh Println and press ctl+space only then IDE will set autocomplete Println().
/// add
Also you have to check this. Is there any exclucde from import and completion?
If doesn't exist, then my last advise is doing invalidate caches/ restart
Related
I am working with JetBrains GoLand and wondering if it's possible to somehow disable the auto removal of unused imports. I have searched the JetBrains forums earlier and there is no such information specifically for Goland.
This feature is used so that you do not receive compilation errors for unused imports from Go. You can deactivate the feature via:
Settings (Preferences) > Go > Imports > Optimize imports on the fly
However my recommendation is to leave this as is and instead let the IDE manage the imports for you.
For example, you can start typing template.New inside the main function and the IDE will ask which "template" package to import as there are two packages in the standard library "text/template" and "html/template". When only one package is available, that will be imported automatically. When you will remove the last reference to the "template" package, the IDE will remove the import automatically, thus allowing you to run the code without any compilation issues.
Another solution is to name your import as "_". For example: import _ "your/package". Doing this will prevent auto removal.
The behavior was slightly changed in the 2021.2 version of GoLand and higher (GO-11362).
Previous behavior (2021.1.3 and lower):
Current one (2021.2 and higher):
So, it was slightly updated and there is no reason to disable Optimize imports on the fly, but as dlsniper said you can start typing your code and import packages later. It is a bit convenient way.
If disabling it doesn't work in File | Settings | Go | Imports | Unchecked Optimized Imports On the fly You can disable it in the on action Save menu
optimize imports enabled in File | Settings | Tools | Actions on Save | Uncheck Optimized Imports
REF: https://youtrack.jetbrains.com/issue/GO-6881/Goland-deletes-code-import-statements-are-deleted-automatically-before-I-even-get-an-opportunity-to-use-them#focus=Comments-27-6124465.0-0
Preferences:
Languages & Frameworks
Go
Imports
Optimize imports on the fly
I have a package collision where I get the following error:
mockgen -package=mocks -source=myproto.pb.go -destination=mocks/my_mocks.go
imported package collision: "foo" imported twice
I see one import that is obvious:
import foo "blah/blah/foo"
But I don't know where to start tracking down the duplicate import (nor where it is coming from). It seems strange to me that this is an issue as I am importing myproto.pb.go just fine, so I'm wondering if there is really an issue w/duplicate imports. Also, GoLand isn't showing any issues.
I'm hoping someone can point me in the direction of getting more information about where the duplicate import is coming form, checking if there is some issue and/or working around the issue.
This seems to be an ongoing issue. I just ran into it with it claiming "rand" was imported twice (even though my code doesn't import "rand").
The following workaround worked for me: Write down the list of interfaces in myproto.pb.go you wish to mock, and use "reflect mode" instead of "source mode"
mockgen -package=mocks -destination=mocks/my_mocks.go path.to/package/containing/myproto/pb/go [space-separated interface names]
should be equivalent to your previous invocation:
mockgen -package=mocks -source=myproto.pb.go -destination=mocks/my_mocks.go
but for some reason is more robust and does not trigger the double-import error.
After upgrading Xcode to 7.3, I just found that some modules are stricken out while importing, like in this screenshot:
But after adding the module (so just pressing enter) everything is fine. What does that mean? The module here is written in Swift and works fine.
This is a bug. We have fixed it in 218010af, which should be included in the Swift 2.2.1 release and is included in the 2016-04-12-a developer snapshot.
The strikethrough occurs if you try to import a module that has already been imported by your file or module:
In this case, I have already imported Foundation (which implicitly imports CoreFoundation), so Xcode is telling you that there is no need to import either module again.
It usually happens when a framework is already imported by any other framework you have already been imported.
For example, UIKit is already imported with Foundation so you don't need to import it manually.
I changed the order of the imports
import Foundation
import UIKit
import LayerKit
import Atlas < red line
import Foundation
import UIKit
import Atlas
import LayerKit
Some notes that may be causing it:
LayerKit importing Atlas even though LayerKit is the lower level API
Atlas is the UI layer
Both were Cocoapod imports
Error appeared when I created an 2nd Schema for App Store/Enteprise
releases and cleaned one and switch to the other.
Deleting Derived
Data didnt clear it.
So tried rearranging them and red line disappeared
I have an OSX project (xcode plugin) and I want to use the ReactiveCocoa paradigms in it (PromiseKit andBrightFutures` are the other implementations of the same paradigms so I need to import at least one from these 3 frameworks/libraries).
The problem is it seems impossible to import them as compiled frameworks into my project because it is plugin. In my project I used dispatch_async and dispatch_after functions only but their nested blocks look awful.
The only solution I found is import one from these frameworks as sources but I don't know how to detach their code. So could anybody help with this trouble? Or maybe are there any other similar libraries which are already represented as source files only?
Short Answer:
Use a dependency manager like Cocoapods or Carthage.
Longer Answer: You can do it manually, but even if you don't want to use any of those, you can look at the .podspec file and see how it's supposed to be used. For example BrightFutures.podspec says:
s.source_files = 'BrightFutures/*.swift'
s.dependency 'Result', '0.6.0-beta.6'
That means that you need to import all the .swift files inside the BrightFutures folder, and that it won't work unless you also import the files from another project called Result.
But please, just let the tools do that for you. You'll be happier. :)
Does anyone know if Visual Studio 2005, 2008, or 2010 has an import suggestion feature like Eclipse does? Maybe I am blatantly overlooking it, but I love Eclipse's auto-suggestions and particularly the import suggestion because I can't for the life of me remember where every single class is located and I always have to resort to Google.
Here is a screenshot of what I am talking about in Eclipse:
The quick fix feature in general is really nice in my opinion, but the import feature I find most useful.
Resharper http://www.jetbrains.com/
I am loving Resharper -- particularly the refactoring / renaming features.
Devexpress CodeRush is also supposed to be good.
(CTRL + .) will bring up a context menu with available imports without having to use resharper :-) for all those using express editions
To extend the answer by sgtz, ReSharper provides several features related to handling unresolved references:
Auto-importing namespaces is useful when you have an existing symbol that is not resolved due to a missing import directive. ReSharper suggests importing a type provided that at least one project in your solution has a corresponding assembly reference.
Import symbol completion helps you complete non-imported types as you're typing them in
A recently added feature is Import types for pasted code: if you're copy-pasting a piece of code, it will import all required types in one go as soon as you've pasted
If an unresolved symbol is actually something you don't mean to reference but instead you'd like to generate a declaration, use Create from usage