Comments (10)
No, you're right - there's no support for this, but definitely something I'll add. I'll have to have a read up on the syntax to make a call on how to make it happen...
from jennifer.
How about:
- "C" import is added by simply using
Qual("C", "foo")
in your code, as is the case for all other imports. - It's treated as a special case when the page renders
- The
Qual
method always renders the upper-case "C" (as is convention). - Imports are usually aliased - with "C" the alias will be suppressed (not sure if this is a requirement?).
- The import is separated below the other imports.
- A new method
CommentC()
is added with the same functionality as "Comment()". The comment (or comments) are rendered directly above the import... So you'd get something like:
import (
fmt "fmt"
baz "foo.bar/baz"
)
// foo
/*
bar
baz
*/
import "C"
func main() {
fmt.Println(C.create_object(), baz.Quz)
}
from jennifer.
That all sounds good to me.
Imports are usually aliased - with "C" the alias will be suppressed (not sure if this is a requirement?).
I'm not sure either, but I've never seen an example of cgo usage with the import aliased. Suppressing the alias sounds like the right thing to do.
from jennifer.
Yes the only reason we always alias the imports is because we don't actually know the package name, so dropping the alias on "C" is perfectly fine. I should have some time tomorrow to implement this.
from jennifer.
Hey - a question: Are there times where you might want to import the "C" pseudo-package, but not reference it in code?
e.g.:
package foo
import "C"
func main() {
// never use C
}
In this case would you use the import _ "C"
syntax?
from jennifer.
If there were to be such a scenario then it would likely be to control a compiler or linker flag, and the import would be preceded by some comment lines.
// #cgo LDFLAGS: -lpng
import "C"
I don't think that I'm likely to need this in my current use cases. But I can't rule it out.
I'm not sure whether import _ "C"
would be recognised by the compiler for cgo purposes. I would need to try it with a simple use case. Unfortunately I won't be in a position to do that for about 10 or 11 hours.
from jennifer.
Yes it looks like "C" is indeed a special case, and can be imported without a "_" even without being used...
from jennifer.
I'm happy with this... Let me know if you think it needs any tweaks.
from jennifer.
BTW @pekim thanks very much for the excellent suggestion, and feel free to open issues if you have any more questions. I'm really glad you're enjoying my work!
from jennifer.
I've just tried it out, and it works nicely. Thank you.
I appreciate that you tag releases, including v0.17.0 with these changes.
from jennifer.
Related Issues (20)
- Better ways to manage import names and aliases HOT 5
- Get *jen.Statement from reflect.Type HOT 1
- Plain struct field tag HOT 1
- Create groups in my code? HOT 19
- [go1.19, go1.20] Indented Multiline Struct Comments have tab characters HOT 3
- example with multiple return types HOT 5
- Support `Array` for `Value` besides `Dict`? HOT 2
- Dict sorts keys by string, breaking existing/natural ordering HOT 2
- Please read: Issues for improving the readability or formatting of outputted code.
- Creating a function receiver HOT 2
- Looking for call chaining including line-feeds HOT 7
- How to generate struct parameter in function qual HOT 2
- Callback with errors?
- Support multiline string literal (backtick) HOT 2
- Feature: ability to provide custom imports sorter function
- Feature Request: Do not render [] if .Types() is called with no arguments HOT 1
- Non-int untyped numeric literal HOT 2
- How to generate complex type field definitions in Struct HOT 3
- Custom types on interface HOT 3
- How to Gennerate var()? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jennifer.