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

lang/go: redo from scratch #1313

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

Xe
Copy link
Contributor

@Xe Xe commented Nov 12, 2023

The former Go bindings do have some useful things, but overall they create invalid syntax more than they should (never). This brave new syntax binding set will do this a lot better.

Replaces #1308

Xe and others added 2 commits November 11, 2023 23:01
The former Go bindings do have some useful things, but overall they
create invalid syntax more than they should (never). This brave new
syntax binding set will do this a lot better.

Replaces talonhub#1308

Signed-off-by: Xe Iaso <[email protected]>
lang/go/go.py Outdated Show resolved Hide resolved
@knausj85
Copy link
Member

knausj85 commented Nov 12, 2023

This looks great, thanks. sadly, I don't know go. As such, I will leave this open so any go experts have the opportunity to take a peek.

@pokey
Copy link
Collaborator

pokey commented Nov 12, 2023

Cc/ @josharian

@josharian
Copy link
Collaborator

Will look early next week. Sorry about the delay.

Copy link
Collaborator

@josharian josharian left a comment

Choose a reason for hiding this comment

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

Some initial thoughts, sorry again for the delay, I'm drowning in other stuff.

@@ -0,0 +1,20 @@
list: user.code_common_function
Copy link
Collaborator

Choose a reason for hiding this comment

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

This it the list of predeclared functions, but many of them aren't very common. (Also: make?)

These are the top ten identifiers across a pretty large Go corpus:

  4.62%   4.62% 10517712 err
  3.14%   7.75% 7149343 nil
  2.64%  10.40% 6019367 string
  2.57%  12.97% 5859233 t
  1.13%  14.09% 2564886 error
  0.99%  15.09% 2267076 c
  0.91%  16.00% 2081426 name
  0.87%  16.87% 1982235 s
  0.83%  17.70% 1881744 _
  0.81%  18.50% 1835017 ctx

len is #16 in the list. append is #35. close is #96. println is #197 (and note that that includes uses of fmt.Println!). clear is #1725. imag doesn't even make the top 5000.

I'd rather not worry about the built-ins and choose based on use.

My 2c: I'd keep len, append, close, cap, clear, delete, max, min, new, panic, and recover. And ditch the rest.

And consider maybe adding important std calls, such as errors.New, fmt.Errorf, fmt.Printf, and the like. If it'd be helpful, I can pull usage stats on those.

FWIW, here's what I have for package fmt (some of which are pretty metal):

# fmt
fmt dot print: fmt.Print
thumped up print: fmt.Print

fmt dot print line: fmt.Println
thumped up print line: fmt.Println

fmt dot print ef: fmt.Printf
thumped up print ef: fmt.Printf
fmt dot print dev: fmt.Printf
thumped up print dev: fmt.Printf
fmt dot print death: fmt.Printf
thumped up print death: fmt.Printf

# # this is how conformer D spells/hears "error eff"
fmt dot erf: fmt.Errorf
thumped up erf: fmt.Errorf

fmt dot sprintf: fmt.Sprintf
thumped up sprintf: fmt.Sprintf
fmt dot sprint dev: fmt.Sprintf
thumped up sprint dev: fmt.Sprintf
fmt dot sprint death: fmt.Sprintf
thumped up sprint death: fmt.Sprintf

Also, there are common identifiers that are hard to pronounce but aren't function calls, like req, resp, cmd. How do those fit in here?

Choose a reason for hiding this comment

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

apologies if i'm misunderstanding the context here

'make' is necessary to initialize maps, slices, chans. its pretty essential

what is the Go corpus you looked at?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, my parenthetical was saying we need make. :)

The corpus: https://github.com/mvdan/corpus

Copy link

@poetworrier poetworrier Nov 15, 2023

Choose a reason for hiding this comment

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

oh man, i worried about that, sorry! The comment I was referring to is My 2c: I'd keep len, append, close, cap, clear, delete, max, min, new, panic, and recover. And ditch the rest.
kinda interesting make doesnt show up that often then?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah. In particular, I'm surprised that new shows up more than make.

Of course, that's a list of all identifiers, not just functions.

integer eight: int8
integer sixteen: int16
integer thirty two: int32
integer sixty four: int64
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe these are more commonly pronounced int sixty four. Here's most of my types talon-list:

int sixty four: int64
int sixty four: int64
you int sixty four: uint64
int thirty two: int32
you int thirty two: uint32
int sixteen: int16
you int sixteen: uint16
int eight: int8
you int eight: uint8
float thirty two: float32
float sixty four: float64
complex sixty four: complex64
complex one twenty eight: complex128
you int pointer: uintptr
you int: uint

append <user.text> [over]:
insert("append(")
insert(user.formatted_text(text, "PRIVATE_CAMEL_CASE"))
[state] context: " ctx "
Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW, I pronounced ctx as cats, to disambiguate with the full word context.

insert(user.formatted_text(text, "PRIVATE_CAMEL_CASE"))
[state] context: " ctx "
[state] context (are you | argue): " ctx context.Context "
state any: " any "

state (air | err): "err"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find err and error to both have high misrecognition rates. This is more idiosyncratic, but I use oops for err and boom for error. Not sure I can fairly foist those on others.

lang/go/go.py Outdated Show resolved Hide resolved

def base_function(text: str, visibility: str):
"""Inserts a public function definition, this assumes a lot about how your editor works"""
result = f"func {actions.user.formatted_text(text, visibility)}() {{\n\n}}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This variable seems unused.

Comment on lines +55 to +58
actions.insert(text)
actions.insert("()")
actions.key("left")
actions.insert(selection)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be simplified to

Suggested change
actions.insert(text)
actions.insert("()")
actions.key("left")
actions.insert(selection)
actions.user.insert_between(f"{text}(", ")")
actions.insert(selection)

or potentially this may have the same side effect in most cases:

Suggested change
actions.insert(text)
actions.insert("()")
actions.key("left")
actions.insert(selection)
actions.user.insert_between(f"{text}({selection}", ")")

else if <user.text> [over]:
insert(" else if ")
insert(user.formatted_text(text, "PRIVATE_CAMEL_CASE"))
settings:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is defining a voice command settings. I think you wanted this to be a settings block.

Suggested change
settings:
settings():

insert("(")
sleep(100ms)
tag(): user.code_comment_block_c_like
tag(): user.code_comment_documentation
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about code_comment_line?

Co-authored-by: David Vo <[email protected]>
@knausj85
Copy link
Member

knausj85 commented Nov 3, 2024

I'm going to convert this one to draft until someone has time to pick it up.

@knausj85 knausj85 marked this pull request as draft November 3, 2024 14:25
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.

6 participants