Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

add go.mod and go.sum support #2344

Merged
merged 2 commits into from
Mar 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,36 @@
"aliases": [
"Go"
]
},
{
"id": "go.mod",
"extensions": [
"go.mod"
],
"aliases": [
"Go Module File"
]
},
{
"id": "go.sum",
"extensions": [
"go.sum"
],
"aliases": [
"Go Checksum File"
]
}
],
"grammars": [
{
"language": "go.mod",
"scopeName": "go.mod",
"path": "./syntaxes/go.mod.tmGrammar.json"
},
{
"language": "go.sum",
"scopeName": "go.sum",
"path": "./syntaxes/go.sum.tmGrammar.json"
}
],
"snippets": [
Expand Down
163 changes: 163 additions & 0 deletions syntaxes/go.mod.tmGrammar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"scopeName": "go.mod",
"patterns": [
{
"include": "#comments"
},
{
"include": "#directive"
}
],
"repository": {
"directive": {
"patterns": [
{
"comment": "Multi-Line directive",
"begin": "(\\w+)\\s+\\(",
"beginCaptures": {
"1": {
"name": "keyword.go.mod"
}
},
"end": "\\)",
"patterns": [
{
"include": "#arguments"
}
]
},
{
"comment": "Single-Line directive",
"match": "(\\w+)\\s+(.*)",
"captures": {
"1": {
"name": "keyword.go.mod"
},
"2": {
"patterns": [
{
"include": "#arguments"
}
]
}
}
}
]
},
"arguments": {
"patterns": [
{
"include": "#comments"
},
{
"include": "#double_quoted_string"
},
{
"include": "#raw_quoted_string"
},
{
"include": "#operator"
},
{
"include": "#semver"
},
{
"include": "#unquoted_string"
}
]
},
"comments": {
"patterns": [
{
"begin": "//",
"beginCaptures": {
"0": {
"name": "punctuation.definition.comment.go.mod"
}
},
"end": "$",
"name": "comment.line.double-slash.go.mod"
}
]
},
"operator": {
"match": "(=>)",
"name": "operator.go.mod"
},
"unquoted_string": {
"comment": "Unquoted string",
"match": "[^\\s]+",
"name": "string.unquoted.go.mod"
},
"double_quoted_string": {
"comment": "Interpreted string literals",
"begin": "\"",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.go.mod"
}
},
"end": "\"",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.go.mod"
}
},
"name": "string.quoted.double",
"patterns": [
{
"include": "#string_escaped_char"
},
{
"include": "#string_placeholder"
}
]
},
"raw_quoted_string": {
"comment": "Raw string literals",
"begin": "`",
"beginCaptures": {
"0": {
"name": "punctuation.definition.string.begin.go.mod"
}
},
"end": "`",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.end.go.mod"
}
},
"name": "string.quoted.raw",
"patterns": [
{
"include": "#string_placeholder"
}
]
},
"semver": {
"comment": "Semver version strings (v1.2.3)",
"match": "v(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(?:-[\\da-z-]+(?:\\.[\\da-z-]+)*)?(?:\\+[\\da-z-]+(?:\\.[\\da-z-]+)*)?",
"name": "constant.language.go.mod"
},
"string_escaped_char": {
"patterns": [
{
"match": "\\\\([0-7]{3}|[abfnrtv\\\\'\"]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})",
"name": "constant.character.escape.go.mod"
},
{
"match": "\\\\[^0-7xuUabfnrtv\\'\"]",
"name": "invalid.illegal.unknown-escape.go.mod"
}
]
},
"string_placeholder": {
"patterns": [
{
"match": "%(\\[\\d+\\])?([\\+#\\-0\\x20]{,2}((\\d+|\\*)?(\\.?(\\d+|\\*|(\\[\\d+\\])\\*?)?(\\[\\d+\\])?)?))?[vT%tbcdoqxXUbeEfFgGsp]",
"name": "constant.other.placeholder.go.mod"
}
]
}
}
}
44 changes: 44 additions & 0 deletions syntaxes/go.sum.tmGrammar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"scopeName": "go.sum",
"patterns": [
{
"include": "#checksum"
},
{
"include": "#semver"
},
{
"include": "#unquoted_string"
}
],
"repository": {
"checksum": {
"comment": "Checksum",
"match": "h1:([^\\s]+)=",
"captures": {
"1": {
"patterns": [
{
"match": "[a-zA-Z\\d+\\/]{43}",
"name": "string.unquoted.go.sum"
},
{
"match": ".*",
"name": "invalid.illegal.unknown-hash.go.sum"
}
]
}
}
},
"semver": {
"comment": "Semver version strings (v1.2.3)",
"match": "v(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)\\.(?:0|[1-9]\\d*)(?:-[\\da-z-]+(?:\\.[\\da-z-]+)*)?(?:\\+[\\da-z-]+(?:\\.[\\da-z-]+)*)?",
Copy link
Contributor

Choose a reason for hiding this comment

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

the "official" regexp is: ^v[0-9]+\.(0\.0-|\d+\.\d+-([^+]*\.)?0\.)\d{14}-[A-Za-z0-9]+(\+incompatible)?$

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's for the special pseudo version: https://tip.golang.org/cmd/go/#hdr-Pseudo_versions

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I agree about using that regex instead - I wrote one by hand on the Atom repo, but we may want to just use the same regex as the one the language uses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is it only matches pseudo versions:

v0.0.0-20161113214103-89cd22812c4f

It won't match

v1.2.3

At least that's how I read the regex. Is there another one that matches both?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are right - the code they use to validate the semver is here.

In testing out your branch locally I didn't experience any problems.

"name": "constant.language.go.sum"
},
"unquoted_string": {
"comment": "Unquoted string",
"match": "[^\\s]+",
"name": "string.unquoted.go.sum"
}
}
}