From 1a930f645d9c70aa9118d7f322159c0478921de9 Mon Sep 17 00:00:00 2001 From: Morcifer <54837467+Morcifer@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:09:14 +0100 Subject: [PATCH] Syntax highlighting for functions, variables and numbers (#2088) Supports syntax highlighting for: - function definitions - function calls - numbers - variables See issue https://github.com/microsoft/qsharp/issues/1950. The change for function calls also applies to operation definitions and to attributes (see bigger example below). The change for variables also applies to attributes and to imports. I might be nice to make attributes and imports get their own designated rules. I can do them as part of this PR, but I think it might be best to do as a followup issue - because I believe this PR is actually already an improvement for them. Simple example for the change (from the original issue description): ![image](https://github.com/user-attachments/assets/cab2630b-0e28-4d48-a98e-7e5bc83e5c7c) And a bigger example: ![image](https://github.com/user-attachments/assets/7d0c059a-8481-4159-ba64-d8539f1540c0) --- vscode/syntaxes/qsharp.tmLanguage.json | 116 +++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/vscode/syntaxes/qsharp.tmLanguage.json b/vscode/syntaxes/qsharp.tmLanguage.json index 051efa236a..d9c390c2a3 100644 --- a/vscode/syntaxes/qsharp.tmLanguage.json +++ b/vscode/syntaxes/qsharp.tmLanguage.json @@ -6,6 +6,9 @@ { "include": "#comments" }, + { + "include": "#functions" + }, { "include": "#keywords" }, @@ -20,6 +23,9 @@ }, { "include": "#strings" + }, + { + "include": "#variables" } ], "repository": { @@ -35,6 +41,103 @@ } ] }, + "functions": { + "patterns": [ + { + "comment": "function definition", + "name": "meta.function.definition.qsharp", + "begin": "\\b(function)\\s+([A-Za-z0-9_]+)(\\()", + "beginCaptures": { + "1": { + "name": "keyword.other.qsharp" + }, + "2": { + "name": "entity.name.function.qsharp" + }, + "3": { + "name": "punctuation.brackets.round.qsharp" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.brackets.round.qsharp" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#functions" + }, + { + "include": "#keywords" + }, + { + "include": "#operators" + }, + { + "include": "#types" + }, + { + "include": "#constants" + }, + { + "include": "#strings" + }, + { + "include": "#variables" + } + ] + }, + { + "comment": "function calls", + "name": "meta.function.call.qsharp", + "begin": "\\b(?