[analysis_server] Fix missing semantic token modifiers for dynamics

This removes `_addIdentifierRegion_dynamicLocal` and just inlines the region kind into the existing variable/name methods, that way the modifiers are still applied without having to duplicate them in `_addIdentifierRegion_dynamicLocal`.

Fixes https://github.com/Dart-Code/Dart-Code/issues/5324

Change-Id: I7f39ec828c916de0fb99d8c71baa78a2f690c94b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392582
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
diff --git a/pkg/analysis_server/lib/src/computer/computer_highlights.dart b/pkg/analysis_server/lib/src/computer/computer_highlights.dart
index 8d47fcf..4ebab3c 100644
--- a/pkg/analysis_server/lib/src/computer/computer_highlights.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_highlights.dart
@@ -119,9 +119,6 @@
     if (_addIdentifierRegion_field(parent, nameToken, element)) {
       return;
     }
-    if (_addIdentifierRegion_dynamicLocal(nameToken, element)) {
-      return;
-    }
     if (_addIdentifierRegion_function(parent, nameToken, element)) {
       return;
     }
@@ -229,23 +226,6 @@
     );
   }
 
-  bool _addIdentifierRegion_dynamicLocal(Token nameToken, Element2? element) {
-    if (element is LocalVariableElement2) {
-      var elementType = element.type;
-      if (elementType is DynamicType) {
-        var type = HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_REFERENCE;
-        return _addRegion_token(nameToken, type);
-      }
-    } else if (element is FormalParameterElement) {
-      var elementType = element.type;
-      if (elementType is DynamicType) {
-        var type = HighlightRegionType.DYNAMIC_PARAMETER_REFERENCE;
-        return _addRegion_token(nameToken, type);
-      }
-    }
-    return false;
-  }
-
   bool _addIdentifierRegion_extension(Token nameToken, Element2? element) {
     if (element is! ExtensionElement2) {
       return false;
@@ -407,7 +387,9 @@
       return false;
     }
     // OK
-    var type = HighlightRegionType.LOCAL_VARIABLE_REFERENCE;
+    var type = element.type is DynamicType
+        ? HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_REFERENCE
+        : HighlightRegionType.LOCAL_VARIABLE_REFERENCE;
     return _addRegion_token(nameToken, type);
   }
 
@@ -438,7 +420,9 @@
     if (element is! FormalParameterElement) {
       return false;
     }
-    var type = HighlightRegionType.PARAMETER_REFERENCE;
+    var type = element.type is DynamicType
+        ? HighlightRegionType.DYNAMIC_PARAMETER_REFERENCE
+        : HighlightRegionType.PARAMETER_REFERENCE;
     var modifiers =
         parent is Label ? {CustomSemanticTokenModifiers.label} : null;
     return _addRegion_token(nameToken, type, semanticTokenModifiers: modifiers);
diff --git a/pkg/analysis_server/test/lsp/semantic_tokens_test.dart b/pkg/analysis_server/test/lsp/semantic_tokens_test.dart
index 1ee840e..b440dbff 100644
--- a/pkg/analysis_server/test/lsp/semantic_tokens_test.dart
+++ b/pkg/analysis_server/test/lsp/semantic_tokens_test.dart
@@ -1337,8 +1337,8 @@
 
   Future<void> test_namedArguments() async {
     var content = '''
-f({String? a}) {
-  f(a: a);
+f({String? a, dynamic b}) {
+  f(a: a, b: b);
 }
 ''';
 
@@ -1348,10 +1348,16 @@
       _Token('String', SemanticTokenTypes.class_),
       _Token('a', SemanticTokenTypes.parameter,
           [SemanticTokenModifiers.declaration]),
+      _Token('dynamic', SemanticTokenTypes.type),
+      _Token('b', SemanticTokenTypes.parameter,
+          [SemanticTokenModifiers.declaration]),
       _Token('f', SemanticTokenTypes.function),
       _Token('a', SemanticTokenTypes.parameter,
           [CustomSemanticTokenModifiers.label]),
       _Token('a', SemanticTokenTypes.parameter),
+      _Token('b', SemanticTokenTypes.parameter,
+          [CustomSemanticTokenModifiers.label]),
+      _Token('b', SemanticTokenTypes.parameter),
     ];
 
     await _initializeAndVerifyTokens(content, expected);