@@ -178,7 +178,9 @@ func (t *Tracker) InsertNodeBefore(sourceFile *ast.SourceFile, before *ast.Node,
178178// InsertModifierBefore inserts a modifier token (like 'type') before a node with a trailing space.
179179func (t * Tracker ) InsertModifierBefore (sourceFile * ast.SourceFile , modifier ast.Kind , before * ast.Node ) {
180180 pos := astnav .GetStartOfNode (before , sourceFile , false )
181- token := sourceFile .GetOrCreateToken (modifier , pos , pos , before .Parent , ast .TokenFlagsNone )
181+ token := t .NewToken (modifier )
182+ token .Loc = core .NewTextRange (pos , pos )
183+ token .Parent = before .Parent
182184 t .InsertNodeAt (sourceFile , core .TextPos (pos ), token , NodeOptions {Suffix : " " })
183185}
184186
@@ -260,9 +262,12 @@ func (t *Tracker) endPosForInsertNodeAfter(sourceFile *ast.SourceFile, after *as
260262 // check if previous statement ends with semicolon
261263 // if not - insert semicolon to preserve the code from changing the meaning due to ASI
262264 endPos := t .converters .PositionToLineAndCharacter (sourceFile , core .TextPos (after .End ()))
265+ semicolon := t .NewToken (ast .KindSemicolonToken )
266+ semicolon .Loc = core .NewTextRange (after .End (), after .End ())
267+ semicolon .Parent = after .Parent
263268 t .ReplaceRange (sourceFile ,
264269 lsproto.Range {Start : endPos , End : endPos },
265- sourceFile . GetOrCreateToken ( ast . KindSemicolonToken , after . End (), after . End (), after . Parent , ast . TokenFlagsNone ) ,
270+ semicolon ,
266271 NodeOptions {},
267272 )
268273 }
@@ -347,7 +352,10 @@ func (t *Tracker) InsertNodeInListAfter(sourceFile *ast.SourceFile, after *ast.N
347352
348353 // insert separator immediately following the 'after' node to preserve comments in trailing trivia
349354 // !!! formatcontext
350- t .ReplaceRange (sourceFile , lsproto.Range {Start : end , End : end }, sourceFile .GetOrCreateToken (separator , after .End (), after .End ()+ len (separatorString ), after .Parent , ast .TokenFlagsNone ), NodeOptions {})
355+ separatorToken := t .NewToken (separator )
356+ separatorToken .Loc = core .NewTextRange (after .End (), after .End ()+ len (separatorString ))
357+ separatorToken .Parent = after .Parent
358+ t .ReplaceRange (sourceFile , lsproto.Range {Start : end , End : end }, separatorToken , NodeOptions {})
351359 // use the same indentation as 'after' item
352360 indentation := format .FindFirstNonWhitespaceColumn (afterStartLinePosition , afterStart , sourceFile , t .formatSettings )
353361 // insert element before the line break on the line that contains 'after' element
0 commit comments