Skip to content

Commit

Permalink
[Go] syntax rework
Browse files Browse the repository at this point in the history
  * Contextual types. Types are scoped where types are expected. There's no whitelist of "known" types.

  * Better understands the language and its syntax. Better at handling whitespace and comments inside complex forms. Better at handling other nuances. Unlikely to be confused by unusual code style.

  * Vars and consts in the root scope are added to the symbol index and searchable by ⌘R, ⌘⇪R, and `goto_definition`.

  * Supports parenthesized `type (...)` groups, not just `const (...)` and `var (...)`.

  * The first argument to `new` and `make` is scoped as a type.

  * Methods declared inside an `interface` are added to the symbol index, reflecting the fact that they actually exist as functions.

  * Supports embedded structs.

  * Supports inherited interfaces.

  * Supports imaginary number literals.

  * Variable declarations are scoped differently from other variable occurrences.

  * `iota` is scoped only in constant initialization expressions.

  * Symbols in ⌘R are annotated with their origin: `var`, `const`, `type` or `func`.

  * Auto-pairing of backticks.

  * Much more comprehensive tests.

  * All keywords and predeclared identifiers are added to auto-completions by default.

  * Better snippets that don't mess with auto-completion.

  * Slightly better indentation rules that more closely match `gofmt`.

Current shortcomings (?):

  * Fewer meta scopes: needs feedback.

  * No support for block labels: needs feedback.
  • Loading branch information
mitranim committed Jul 14, 2018
1 parent 289782f commit 984f814
Show file tree
Hide file tree
Showing 32 changed files with 3,564 additions and 1,043 deletions.
39 changes: 0 additions & 39 deletions Go/Comments.tmPreferences

This file was deleted.

45 changes: 45 additions & 0 deletions Go/Default.sublime-keymap
@@ -0,0 +1,45 @@
[
// Auto-pair backquotes. Partially copied from the default Sublime keymap,
// with some modifications.
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`$0`"}, "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.go", },
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "(?:^|\\s)$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\\s|$)", "match_all": true },
]
},
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`${0:$SELECTION}`"}, "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.go", },
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
]
},
{ "keys": ["`"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "key": "selector", "operator": "equal", "operand": "source.go", },
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true },
]
},
{ "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete Left Right.sublime-macro"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "`$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true },
]
},

{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\($", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true }
]
},
]
71 changes: 71 additions & 0 deletions Go/Go.sublime-completions
@@ -0,0 +1,71 @@
{
"scope": "source.go",

"completions": [
// https://golang.org/ref/spec#Keywords
"break",
"default",
"func",
"interface",
"select",
"case",
"defer",
"go",
"map",
"struct",
"chan",
"else",
"goto",
"package",
"switch",
"const",
"fallthrough",
"if",
"range",
"type",
"continue",
"for",
"import",
"return",
"var",

// https://golang.org/ref/spec#Predeclared_identifiers
"bool",
"byte",
"complex64",
"complex128",
"error",
"float32",
"float64",
"int",
"int8",
"int16",
"int32",
"int64",
"rune",
"string",
"uint",
"uint8",
"uint16",
"uint32",
"uint64",
"uintptr",
"true",
"false",
"iota",
"nil",
"append",
"cap",
"close",
"complex",
"copy",
"delete",
"imag",
"len",
"make",
"new",
"panic",
"real",
"recover",
],
}
11 changes: 11 additions & 0 deletions Go/Go.sublime-settings
@@ -0,0 +1,11 @@
{
// Prefer tabs because gofmt enforces tabs.
"translate_tabs_to_spaces": false,
// Trigger autocompletion on dot access.
"auto_complete_triggers": [
{
"characters": ".",
"selector": "source.go",
},
],
}

0 comments on commit 984f814

Please sign in to comment.