-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some function call highlighting issues.
This fixes a number of incorrect highlights surrounding function calls. Due to the ambiguity in the syntax tree, the function call highlighting is not perfect, however a couple known highlighting issues were fixed, including generic package instantiation, array assignments, attribute function calls, etc. Additionally, a troubleshooting section was added for this topic to the documantation to document the known issue and suggest workarounds.
- Loading branch information
Showing
6 changed files
with
409 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
;; Author: Troy Brown <[email protected]> | ||
;; Created: February 2023 | ||
;; Version: 0.6.0 | ||
;; Version: 0.6.1 | ||
;; Keywords: ada languages tree-sitter | ||
;; URL: https://github.com/brownts/ada-ts-mode | ||
;; Package-Requires: ((emacs "29.1")) | ||
|
@@ -226,6 +226,7 @@ the string property to those instances." | |
:feature 'attribute | ||
'(((attribute_designator) @font-lock-property-use-face) | ||
(range_attribute_designator "range" @font-lock-property-use-face) | ||
(reduction_attribute_designator (identifier) @font-lock-property-use-face) | ||
(component_declaration (identifier) @font-lock-property-name-face) | ||
(component_choice_list (identifier) @font-lock-property-name-face) | ||
(component_clause local_name: _ @font-lock-property-name-face)) | ||
|
@@ -308,10 +309,18 @@ the string property to those instances." | |
(generic_instantiation | ||
["procedure" "function"] | ||
generic_name: [(identifier) (string_literal)] @font-lock-function-name-face) | ||
(generic_instantiation | ||
["procedure" "function"] | ||
generic_name: (function_call name: [(identifier) (string_literal)] | ||
@font-lock-function-name-face)) | ||
(generic_instantiation | ||
["procedure" "function"] | ||
generic_name: (selected_component | ||
selector_name: _ @font-lock-function-name-face)) | ||
(generic_instantiation | ||
["procedure" "function"] | ||
generic_name: (function_call name: (selected_component | ||
selector_name: _ @font-lock-function-name-face))) | ||
(subprogram_renaming_declaration | ||
callable_entity_name: [(identifier) (string_literal)] @font-lock-function-name-face) | ||
(subprogram_renaming_declaration | ||
|
@@ -366,16 +375,54 @@ the string property to those instances." | |
;; Function/Procedure Calls | ||
:language 'ada | ||
:feature 'function | ||
'((function_call | ||
name: [(identifier) (string_literal)] @font-lock-function-call-face) | ||
(function_call | ||
name: (selected_component | ||
selector_name: _ @font-lock-function-call-face)) | ||
:override 'prepend | ||
'(((function_call | ||
name: [(identifier) (string_literal)] @font-lock-function-call-face | ||
:anchor (comment) :* | ||
:anchor (actual_parameter_part)) | ||
@function-call | ||
(:pred ada-ts-mode--named-function-call-p @function-call)) | ||
((function_call | ||
name: (selected_component | ||
selector_name: _ @font-lock-function-call-face) | ||
:anchor (comment) :* | ||
:anchor (actual_parameter_part)) | ||
@function-call | ||
(:pred ada-ts-mode--named-function-call-p @function-call)) | ||
(function_call (attribute_designator) @font-lock-function-call-face | ||
:anchor (comment) :* | ||
:anchor (actual_parameter_part)) | ||
((procedure_call_statement | ||
name: (identifier) @font-lock-function-call-face :anchor) | ||
@procedure-call | ||
(:pred ada-ts-mode--named-procedure-call-p @procedure-call)) | ||
((procedure_call_statement | ||
name: (identifier) @font-lock-function-call-face | ||
:anchor (comment) :* | ||
:anchor (actual_parameter_part)) | ||
@procedure-call | ||
(:pred ada-ts-mode--named-procedure-call-p @procedure-call)) | ||
((procedure_call_statement | ||
name: (selected_component | ||
selector_name: (identifier) @font-lock-function-call-face) | ||
:anchor) | ||
@procedure-call | ||
(:pred ada-ts-mode--named-procedure-call-p @procedure-call)) | ||
((procedure_call_statement | ||
name: (selected_component | ||
selector_name: (identifier) @font-lock-function-call-face) | ||
:anchor (comment) :* | ||
:anchor (actual_parameter_part)) | ||
@procedure-call | ||
(:pred ada-ts-mode--named-procedure-call-p @procedure-call)) | ||
(procedure_call_statement | ||
name: (identifier) @font-lock-function-call-face) | ||
(attribute_designator) @font-lock-function-call-face :anchor) | ||
(procedure_call_statement | ||
name: (selected_component | ||
selector_name: (identifier) @font-lock-function-call-face))) | ||
(attribute_designator) @font-lock-function-call-face | ||
:anchor (comment) :* | ||
:anchor (actual_parameter_part)) | ||
(reduction_attribute_designator | ||
(identifier) @font-lock-function-call-face)) | ||
|
||
;; Keywords | ||
:language 'ada | ||
|
@@ -492,6 +539,29 @@ the string property to those instances." | |
|
||
"Font-lock settings for `ada-ts-mode'.") | ||
|
||
(defun ada-ts-mode--named-function-call-p (node) | ||
"Check if NODE is a named function call. | ||
Certain places use a function_call node in the syntax tree, such as a | ||
generic instantiation, because it has similar syntax to a function call, | ||
but it isn't an actual function call." | ||
(let ((node-type (treesit-node-type node)) | ||
(parent-node-type (treesit-node-type (treesit-node-parent node)))) | ||
(and (string-equal node-type "function_call") | ||
(not (string-equal parent-node-type "generic_instantiation")) | ||
(not (string-equal parent-node-type "assignment_statement")) | ||
(let ((function-name (ada-ts-mode--node-to-name | ||
(treesit-node-child-by-field-name node "name")))) | ||
(not (string-suffix-p ".all" function-name 'ignore-case)))))) | ||
|
||
(defun ada-ts-mode--named-procedure-call-p (node) | ||
"Check if NODE is a named procedure call." | ||
(let ((node-type (treesit-node-type node))) | ||
(and (string-equal node-type "procedure_call_statement") | ||
(let ((procedure-name (ada-ts-mode--node-to-name | ||
(treesit-node-child-by-field-name node "name")))) | ||
(not (string-suffix-p ".all" procedure-name 'ignore-case)))))) | ||
|
||
(defun ada-ts-mode--mode-in-p (node) | ||
"Check if mode for NODE is \\='in\\='." | ||
(let ((mode-node | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package body Test is | ||
|
||
A1 : Address := System'To_Address (16#0000_0000#); | ||
-- ^ nil | ||
-- ^ (font-lock-function-call-face font-lock-property-use-face) | ||
|
||
A2 : Address := System.To_Address (16#0000_0000#); | ||
-- ^ nil | ||
-- ^ font-lock-function-call-face | ||
|
||
I1 : Integer := Integer'Min (5, 6); | ||
-- ^ nil | ||
-- ^ (font-lock-function-call-face font-lock-property-use-face) | ||
|
||
I2 : Integer := Standard.Integer'Min (5, 6); | ||
-- ^ ^ nil | ||
-- ^ (font-lock-function-call-face font-lock-property-use-face) | ||
|
||
I3 : Integer := Integer (5); | ||
-- ^ font-lock-function-call-face | ||
|
||
I4 : Integer := Standard.Integer (5); | ||
-- ^ nil | ||
-- ^ font-lock-function-call-face | ||
|
||
X1 : Integer := Foo.all (5); | ||
-- ^ nil | ||
-- ^ font-lock-keyword-face | ||
|
||
X2 : Integer := Foo.ALL (5); | ||
-- ^ nil | ||
-- ^ font-lock-keyword-face | ||
|
||
X3 : Integer := XYZ.Foo.all (5); | ||
-- ^ ^ nil | ||
-- ^ font-lock-keyword-face | ||
|
||
X4 : Integer := XYZ.Foo.ALL (5); | ||
-- ^ ^ nil | ||
-- ^ font-lock-keyword-face | ||
|
||
X5 : Integer := XYZ.Foo.Ball (5); | ||
-- ^ ^ nil | ||
-- ^ font-lock-function-call-face | ||
|
||
X6 : Integer := XYZ.Foo.BALL (5); | ||
-- ^ ^ nil | ||
-- ^ font-lock-function-call-face | ||
|
||
X7 : Integer := Foo'Reduce ("+", 0); | ||
-- ^ nil | ||
-- ^ (font-lock-function-call-face font-lock-property-use-face) | ||
|
||
X8 : Integer := XYZ.Foo'Reduce ("+", 0); | ||
-- ^ ^ nil | ||
-- ^ (font-lock-function-call-face font-lock-property-use-face) | ||
|
||
X9 : Integer := [for J in 1 .. 10 => J]'Reduce ("*", 1); | ||
-- ^ (font-lock-function-call-face font-lock-property-use-face) | ||
|
||
X10 : Integer := Integer'Mod (5); | ||
-- ^ nil | ||
-- ^ (font-lock-function-call-face font-lock-property-use-face) | ||
|
||
X11 : Integer := "+" (1, 2); | ||
-- ^ font-lock-function-call-face | ||
|
||
X12 : Integer := XYZ."+" (1, 2); | ||
-- ^ nil | ||
-- ^ font-lock-function-call-face | ||
|
||
end Test; |
Oops, something went wrong.