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

Crash on a custom syntax file with a Swift shebang #3450

Closed
frkd-dev opened this issue Sep 4, 2024 · 6 comments
Closed

Crash on a custom syntax file with a Swift shebang #3450

frkd-dev opened this issue Sep 4, 2024 · 6 comments

Comments

@frkd-dev
Copy link
Contributor

frkd-dev commented Sep 4, 2024

Description of the problem or steps to reproduce

Preamble
The Micro has syntax support for Swift language, but only when filenames end with the .swift extension. Unfortunately, it doesn't recognize a shebang #!/usr/bin/swift and no syntax highlighting as the result. The shebang is totally valid on macOS, as that's the official Swift interpreter.

Problem
I decided to create a custom syntax file ~/.config/micro/syntax/swift.yaml with the following content:

filetype: swift
detect:
    header: "#!/usr/bin/swift"

Now, whenever I create a new file, add a shebang #!/usr/bin/swift, and then save it, the editor crashes every time with the following output:

Micro encountered an error: runtime.errorString runtime error: invalid memory address or nil pointer dereference
runtime/panic.go:261 (0x1007a381c)
runtime/signal_unix.go:861 (0x1007a37e9)
github.com/zyedidia/micro/v2/pkg/highlight/parser.go:217 (0x100b53e9d)
github.com/zyedidia/micro/v2/internal/buffer/buffer.go:775 (0x100b5d504)
github.com/zyedidia/micro/v2/internal/buffer/save.go:219 (0x100b682a4)
github.com/zyedidia/micro/v2/internal/buffer/save.go:98 (0x100b98c20)
github.com/zyedidia/micro/v2/internal/action/actions.go:829 (0x100b98bf5)
github.com/zyedidia/micro/v2/internal/action/actions.go:765 (0x100b985a0)
github.com/zyedidia/micro/v2/internal/action/actions.go:775 (0x100b9861c)
github.com/zyedidia/micro/v2/internal/action/bufpane.go:545 (0x100ba390c)
github.com/zyedidia/micro/v2/internal/action/bufpane.go:150 (0x100ba1f8c)
github.com/zyedidia/micro/v2/internal/action/bufpane.go:32 (0x100ba1d70)
github.com/zyedidia/micro/v2/internal/action/bufpane.go:528 (0x100ba368c)
github.com/zyedidia/micro/v2/internal/action/bufpane.go:444 (0x100ba3200)
github.com/zyedidia/micro/v2/internal/action/tab.go:269 (0x100bb1e3c)
github.com/zyedidia/micro/v2/internal/action/tab.go:139 (0x100bb13e8)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:476 (0x100be8714)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:394 (0x100be7f98)
runtime/internal/atomic/types.go:194 (0x10078e15c)
runtime/asm_arm64.s:1197 (0x1007c0f04)

If I open an already existing file with the same shebang, I get a crash with the following output:

Micro encountered an error: runtime.errorString runtime error: invalid memory address or nil pointer dereference
runtime/panic.go:261 (0x104e9b81c)
runtime/signal_unix.go:861 (0x104e9b7e9)
github.com/zyedidia/micro/v2/pkg/highlight/parser.go:217 (0x10524be9d)
github.com/zyedidia/micro/v2/internal/buffer/buffer.go:775 (0x105255504)
github.com/zyedidia/micro/v2/internal/buffer/buffer.go:392 (0x105253088)
github.com/zyedidia/micro/v2/internal/buffer/buffer.go:261 (0x105251f20)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:203 (0x1052df474)
github.com/zyedidia/micro/v2/cmd/micro/micro.go:331 (0x1052dfc10)
runtime/internal/atomic/types.go:194 (0x104e8615c)
runtime/asm_arm64.s:1197 (0x104eb8f04)

Both stacktraces are pointing at this line.

Specifications

The micro is installed using macports.

Version: 2.0.13
Commit hash: unknown
Compiled on January 12, 2024

@JoeKar
Copy link
Collaborator

JoeKar commented Sep 4, 2024

You should better start by copying something present to your local config folder (e.g. https://github.com/zyedidia/micro/blob/master/runtime/syntax/awk.yaml). The problem is that you define your syntax file without top level rules (it's mandatory). Without it there wouldn't be anything to highlight anyway.

PS:
I plan to refactor the code to transform rules to be optionally...at for nesting in regions. For the top level rules indeed some more robustness and error log would be helpful.

@frkd-dev
Copy link
Contributor Author

frkd-dev commented Sep 4, 2024

Okay, I misunderstood the intention of syntax files, and they should be full-fledged highlighting rules. I'll remove my invalid syntax file, as I don't want to completely override the original rules.

Could you kindly add a shebang to the swift.yaml then? I would do that, but I don't think this one-liner deserves a PR.

@frkd-dev frkd-dev closed this as not planned Won't fix, can't repro, duplicate, stale Sep 4, 2024
@JoeKar
Copy link
Collaborator

JoeKar commented Sep 4, 2024

Oh, most probably misunderstood you too. You can workaround the current situation by using the following custom ~/.config/micro/syntax/swift.yaml:

filetype: swift

detect:
    filename: "\\.swift$"
    header: "^#!.*bin/(env +)?swift( |$)"

rules:
    - include: "swift"

It includes the rules of the builtin definition, but extends them with the own header definition.

I would do that, but I don't think this one-liner deserves a PR.

Sure you can, you've the example present above. 😉

@frkd-dev
Copy link
Contributor Author

frkd-dev commented Sep 4, 2024

Opened a PR #3451

@dmaluka
Copy link
Collaborator

dmaluka commented Sep 7, 2024

FWIW, the crash was fixed by #3213. The fix is present in 2.0.14.

@JoeKar
Copy link
Collaborator

JoeKar commented Sep 7, 2024

Ah, right. Already forgot this. 👍

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

No branches or pull requests

4 participants
@frkd-dev @dmaluka @JoeKar and others