2424import com .github ._1c_syntax .bsl .languageserver .context .DocumentContext ;
2525import com .github ._1c_syntax .bsl .languageserver .context .symbol .ParameterDefinition ;
2626import com .github ._1c_syntax .bsl .languageserver .context .symbol .SymbolTree ;
27+ import com .github ._1c_syntax .bsl .languageserver .context .symbol .VariableSymbol ;
2728import com .github ._1c_syntax .bsl .languageserver .context .symbol .description .MethodDescription ;
2829import com .github ._1c_syntax .bsl .languageserver .context .symbol .description .SourceDefinedSymbolDescription ;
2930import com .github ._1c_syntax .bsl .languageserver .context .symbol .variable .VariableDescription ;
31+ import com .github ._1c_syntax .bsl .languageserver .context .symbol .variable .VariableKind ;
3032import com .github ._1c_syntax .bsl .languageserver .events .LanguageServerInitializeRequestReceivedEvent ;
3133import com .github ._1c_syntax .bsl .languageserver .references .ReferenceIndex ;
3234import com .github ._1c_syntax .bsl .languageserver .references .ReferenceResolver ;
3335import com .github ._1c_syntax .bsl .languageserver .references .model .OccurrenceType ;
36+ import com .github ._1c_syntax .bsl .languageserver .references .model .Reference ;
3437import com .github ._1c_syntax .bsl .languageserver .utils .Ranges ;
3538import com .github ._1c_syntax .bsl .languageserver .utils .Trees ;
3639import com .github ._1c_syntax .bsl .parser .BSLLexer ;
@@ -237,10 +240,13 @@ private void addVariableSymbols(
237240 BitSet documentationLines
238241 ) {
239242 for (var variableSymbol : symbolTree .getVariables ()) {
243+ if (variableSymbol .getKind () == VariableKind .PARAMETER ) {
244+ continue ;
245+ }
246+
240247 var nameRange = variableSymbol .getVariableNameRange ();
241248 if (!Ranges .isEmpty (nameRange )) {
242- Position pos = nameRange .getStart ();
243- boolean isDefinition = referenceResolver .findReference (documentContext .getUri (), pos )
249+ boolean isDefinition = referenceResolver .findReference (documentContext .getUri (), nameRange .getStart ())
244250 .map (ref -> ref .getOccurrenceType () == OccurrenceType .DEFINITION )
245251 .orElse (false );
246252 if (isDefinition ) {
@@ -249,6 +255,7 @@ private void addVariableSymbols(
249255 addRange (entries , nameRange , SemanticTokenTypes .Variable );
250256 }
251257 }
258+
252259 variableSymbol .getDescription ().ifPresent ((VariableDescription description ) -> {
253260 processVariableDescription (descriptionRanges , documentationLines , description );
254261
@@ -257,14 +264,32 @@ private void addVariableSymbols(
257264 );
258265 });
259266 }
267+
268+ var references = referenceIndex .getReferencesFrom (documentContext .getUri (), SymbolKind .Variable );
269+ references .stream ()
270+ .filter (Reference ::isSourceDefinedSymbolReference )
271+ .forEach (reference -> reference .getSourceDefinedSymbol ()
272+ .filter (symbol -> symbol instanceof VariableSymbol )
273+ .map (symbol -> (VariableSymbol ) symbol )
274+ .ifPresent (variableSymbol -> {
275+ var tokenType = variableSymbol .getKind () == VariableKind .PARAMETER
276+ ? SemanticTokenTypes .Parameter
277+ : SemanticTokenTypes .Variable ;
278+
279+ if (reference .getOccurrenceType () == OccurrenceType .DEFINITION ) {
280+ addRange (entries , reference .getSelectionRange (), tokenType , SemanticTokenModifiers .Definition );
281+ } else {
282+ addRange (entries , reference .getSelectionRange (), tokenType );
283+ }
284+ }));
260285 }
261286
262287 private void addMethodSymbols (SymbolTree symbolTree , List <TokenEntry > entries , List <Range > descriptionRanges , BitSet documentationLines ) {
263288 for (var method : symbolTree .getMethods ()) {
264289 var semanticTokenType = method .isFunction () ? SemanticTokenTypes .Function : SemanticTokenTypes .Method ;
265290 addRange (entries , method .getSubNameRange (), semanticTokenType );
266291 for (ParameterDefinition parameter : method .getParameters ()) {
267- addRange (entries , parameter .getRange (), SemanticTokenTypes .Parameter );
292+ addRange (entries , parameter .getRange (), SemanticTokenTypes .Parameter , SemanticTokenModifiers . Definition );
268293 }
269294 method .getDescription ().ifPresent ((MethodDescription description ) ->
270295 processVariableDescription (descriptionRanges , documentationLines , description )
0 commit comments