Skip to content

Commit bce06ae

Browse files
committed
small fixes
1 parent e314d60 commit bce06ae

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

editors/code/src/languages/syntaxes/tolk.tmLanguage.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ describe("Tolk TextMate grammar", () => {
136136
expect(nominalTypeRegex.exec("SendResultList")?.[0]).toBe("SendResultList")
137137
})
138138

139+
it("scopes chained method calls as functions", () => {
140+
const grammar = readTolkGrammar()
141+
const functionPattern = grammar.patterns.find(
142+
pattern => pattern.captures?.["2"]?.name === "entity.name.function",
143+
)
144+
const functionRegex = new RegExp(functionPattern?.match ?? "", "u")
145+
const scopedFunctionName = (source: string): string | null =>
146+
functionRegex.exec(source)?.[2] ?? null
147+
148+
expect(functionPattern?.captures?.["1"]?.name).toBe("keyword.operator.accessor")
149+
expect(scopedFunctionName(".toHaveSuccessfulTx<ProcessGovernanceDecision>(")).toBe(
150+
"toHaveSuccessfulTx",
151+
)
152+
expect(scopedFunctionName(".bar()")).toBe("bar")
153+
expect(scopedFunctionName(".bar<A>()")).toBe("bar")
154+
expect(scopedFunctionName("bar()")).toBe("bar")
155+
156+
expect(scopedFunctionName(".bar")).toBeNull()
157+
expect(scopedFunctionName(".bar<A>")).toBeNull()
158+
})
159+
139160
it("scopes dotted annotation names without scoping dots", () => {
140161
const grammar = readTolkGrammar()
141162
const annotationPattern = grammar.patterns.find(pattern => pattern.begin?.startsWith("(@)"))

syntaxes/tolk.tmLanguage.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@
9999
]
100100
},
101101
{
102-
"name": "entity.name.function",
103-
"match": "(?<!\\.)(`[^`]+`|[a-zA-Z$_][a-zA-Z0-9$_]*)(?=\\s*(?:<[^()\\n]*>)?\\s*\\()"
102+
"match": "(\\.)?(`[^`]+`|[a-zA-Z$_][a-zA-Z0-9$_]*)(?=\\s*(?:<[^()\\n]*>)?\\s*\\()",
103+
"captures": {
104+
"1": {"name": "keyword.operator.accessor"},
105+
"2": {"name": "entity.name.function"}
106+
}
104107
},
105108
{
106109
"name": "entity.name.type",

0 commit comments

Comments
 (0)