From 0bc510b6d954dbab9d120aca8e7ce8144798e33e Mon Sep 17 00:00:00 2001 From: yu2971512385-ui <287936273+yu2971512385-ui@users.noreply.github.com> Date: Wed, 30 Sep 2026 12:01:16 +0800 Subject: [PATCH 1/2] Highlight the Go predeclared identifiers any, comparable, clear, max and min The Go mode lists the predeclared types (error, rune, string, ...) and functions (append, len, make, ...), but not the identifiers the language gained later: any and comparable (Go 1.18, with generics) and clear, max and min (Go 1.21). Co-Authored-By: Claude Opus 5 (1M context) --- src/mode/golang_highlight_rules.js | 7 ++++--- src/mode/golang_test.js | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/mode/golang_highlight_rules.js b/src/mode/golang_highlight_rules.js index b81377533c5..4e881b393b7 100644 --- a/src/mode/golang_highlight_rules.js +++ b/src/mode/golang_highlight_rules.js @@ -10,11 +10,12 @@ var oop = require("../lib/oop"); "select|type|var" ); var builtinTypes = ( - "string|uint8|uint16|uint32|uint64|int8|int16|int32|int64|float32|" + - "float64|complex64|complex128|byte|rune|uint|int|uintptr|bool|error" + "any|string|uint8|uint16|uint32|uint64|int8|int16|int32|int64|float32|" + + "float64|complex64|complex128|byte|rune|uint|int|uintptr|bool|error|comparable" ); var builtinFunctions = ( - "new|close|cap|copy|panic|panicln|print|println|len|make|delete|real|recover|imag|append" + "new|close|cap|copy|panic|panicln|print|println|len|make|delete|real|recover|imag|append|" + + "clear|max|min" ); var builtinConstants = ("nil|true|false|iota"); diff --git a/src/mode/golang_test.js b/src/mode/golang_test.js index 090d9347f73..6bd5c315911 100644 --- a/src/mode/golang_test.js +++ b/src/mode/golang_test.js @@ -9,6 +9,19 @@ module.exports = { this.mode = new GolangMode(); }, + "test: predeclared identifiers added in Go 1.18 and 1.21" : function() { + var tokenizer = this.mode.getTokenizer(); + function typeOf(line, index) { + return tokenizer.getLineTokens(line, "start").tokens[index].type; + } + assert.equal("support.type", typeOf("var x any", 4)); + assert.equal("support.type", typeOf("type S[E comparable] int", 6)); + assert.equal("support.function", typeOf("clear(m)", 0)); + assert.equal("support.function", typeOf("min(1, 2)", 0)); + assert.equal("support.function", typeOf("max(1, 2)", 0)); + assert.equal("support.type", typeOf("var e error", 4)); + }, + "test: trigger outdent if line is space and new text starts with closing brace or paren" : function() { assert.ok(this.mode.checkOutdent("start", " ", " }")); assert.ok(this.mode.checkOutdent("start", " ", " )")); From e690c632c99727a996d5d4965ea9cfc7ec23453b Mon Sep 17 00:00:00 2001 From: yu2971512385-ui <287936273+yu2971512385-ui@users.noreply.github.com> Date: Wed, 30 Sep 2026 16:32:48 +0800 Subject: [PATCH 2/2] Drop the builtin functions from this change clear, max and min are already scoped as support.function wherever they are called, because the mode scopes any identifier followed by "(" that way. Adding them to builtinFunctions only changes how they look outside call position, where they are ordinary identifiers that a program may well have shadowed, so leave that alone and keep this change to the two predeclared types. Co-Authored-By: Claude Opus 5 (1M context) --- src/mode/golang_highlight_rules.js | 3 +-- src/mode/golang_test.js | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/mode/golang_highlight_rules.js b/src/mode/golang_highlight_rules.js index 4e881b393b7..8dd0d2d5ff2 100644 --- a/src/mode/golang_highlight_rules.js +++ b/src/mode/golang_highlight_rules.js @@ -14,8 +14,7 @@ var oop = require("../lib/oop"); "float64|complex64|complex128|byte|rune|uint|int|uintptr|bool|error|comparable" ); var builtinFunctions = ( - "new|close|cap|copy|panic|panicln|print|println|len|make|delete|real|recover|imag|append|" + - "clear|max|min" + "new|close|cap|copy|panic|panicln|print|println|len|make|delete|real|recover|imag|append" ); var builtinConstants = ("nil|true|false|iota"); diff --git a/src/mode/golang_test.js b/src/mode/golang_test.js index 6bd5c315911..83869e46ed8 100644 --- a/src/mode/golang_test.js +++ b/src/mode/golang_test.js @@ -9,16 +9,13 @@ module.exports = { this.mode = new GolangMode(); }, - "test: predeclared identifiers added in Go 1.18 and 1.21" : function() { + "test: predeclared types added in Go 1.18" : function() { var tokenizer = this.mode.getTokenizer(); function typeOf(line, index) { return tokenizer.getLineTokens(line, "start").tokens[index].type; } assert.equal("support.type", typeOf("var x any", 4)); assert.equal("support.type", typeOf("type S[E comparable] int", 6)); - assert.equal("support.function", typeOf("clear(m)", 0)); - assert.equal("support.function", typeOf("min(1, 2)", 0)); - assert.equal("support.function", typeOf("max(1, 2)", 0)); assert.equal("support.type", typeOf("var e error", 4)); },