@@ -74,6 +74,15 @@ public static BicepCompletionContext Create(SyntaxTree syntaxTree, int offset)
7474 // this indicates a bug
7575 throw new ArgumentException ( $ "The specified offset { offset } is outside the span of the specified { nameof ( ProgramSyntax ) } node.") ;
7676 }
77+
78+ // the check at the beginning guarantees we have at least 1 node
79+ var replacementRange = GetReplacementRange ( syntaxTree , matchingNodes [ ^ 1 ] , offset ) ;
80+
81+ var matchingTriviaType = FindTriviaMatchingOffset ( syntaxTree . ProgramSyntax , offset ) ? . Type ;
82+ if ( matchingTriviaType is not null && ( matchingTriviaType == SyntaxTriviaType . MultiLineComment || matchingTriviaType == SyntaxTriviaType . SingleLineComment ) ) {
83+ //we're in a comment, no hints here
84+ return new BicepCompletionContext ( BicepCompletionContextKind . None , replacementRange , null , null , null , null , null , null , null ) ;
85+ }
7786
7887 var declarationInfo = FindLastNodeOfType < INamedDeclarationSyntax , SyntaxBase > ( matchingNodes ) ;
7988 var objectInfo = FindLastNodeOfType < ObjectSyntax , ObjectSyntax > ( matchingNodes ) ;
@@ -102,9 +111,6 @@ public static BicepCompletionContext Create(SyntaxTree syntaxTree, int offset)
102111 kind |= ConvertFlag ( IsInnerExpressionContext ( matchingNodes ) , BicepCompletionContextKind . Expression ) ;
103112 }
104113
105- // the check at the beginning guarantees we have at least 1 node
106- var replacementRange = GetReplacementRange ( syntaxTree , matchingNodes [ ^ 1 ] , offset ) ;
107-
108114 return new BicepCompletionContext ( kind , replacementRange , declarationInfo . node , objectInfo . node , propertyInfo . node , arrayInfo . node , propertyAccessInfo . node , arrayAccessInfo . node , targetScopeInfo . node ) ;
109115 }
110116
@@ -133,6 +139,16 @@ private static List<SyntaxBase> FindNodesMatchingOffset(ProgramSyntax syntax, in
133139 return nodes ;
134140 }
135141
142+ /// <summary>
143+ /// Returnes trivia which span contains the specified offset.
144+ /// </summary>
145+ /// <param name="syntax">The program node</param>
146+ /// <param name="offset">The offset</param>
147+ private static SyntaxTrivia ? FindTriviaMatchingOffset ( ProgramSyntax syntax , int offset )
148+ {
149+ return syntax . TryFindMostSpecificTriviaInclusive ( offset , current => true ) ;
150+ }
151+
136152 private static BicepCompletionContextKind ConvertFlag ( bool value , BicepCompletionContextKind flag ) => value ? flag : BicepCompletionContextKind . None ;
137153
138154 private static BicepCompletionContextKind GetDeclarationTypeFlags ( IList < SyntaxBase > matchingNodes , int offset )
0 commit comments