@@ -303,20 +303,35 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
303303 !unexpected. trailingTrivia. isEmpty,
304304 token. isMissing
305305 {
306- let fixIt = FixIt (
307- message: . removeExtraneousWhitespace,
308- changes: [
309- . makeMissing( unexpected, transferTrivia: false ) , // don't transfer trivia because trivia is the issue here
310- . makePresent( token, leadingTrivia: unexpected. leadingTrivia) ,
311- ]
312- )
313- addDiagnostic (
314- token,
315- position: unexpected. endPositionBeforeTrailingTrivia,
316- ExtraneousWhitespace ( tokenWithWhitespace: unexpected) ,
317- fixIts: [ fixIt] ,
318- handledNodes: [ token. id, unexpected. id]
319- )
306+ let changes : [ FixIt . MultiNodeChange ] = [
307+ . makeMissing( unexpected, transferTrivia: false ) , // don't transfer trivia because trivia is the issue here
308+ . makePresent( token, leadingTrivia: unexpected. leadingTrivia) ,
309+ ]
310+ if let nextToken = token. nextToken ( viewMode: . all) ,
311+ nextToken. isMissing
312+ {
313+ // If the next token is missing, the problem here isn’t actually the
314+ // space after token but that the missing token should be added after
315+ // `token` without a space. Generate a diagnsotic for that.
316+ _ = handleMissingSyntax (
317+ nextToken,
318+ overridePosition: unexpected. endPositionBeforeTrailingTrivia,
319+ additionalChanges: changes,
320+ additionalHandledNodes: [ unexpected. id, token. id]
321+ )
322+ } else {
323+ let fixIt = FixIt (
324+ message: . removeExtraneousWhitespace,
325+ changes: changes
326+ )
327+ addDiagnostic (
328+ token,
329+ position: unexpected. endPositionBeforeTrailingTrivia,
330+ ExtraneousWhitespace ( tokenWithWhitespace: unexpected) ,
331+ fixIts: [ fixIt] ,
332+ handledNodes: [ token. id, unexpected. id]
333+ )
334+ }
320335 }
321336 }
322337
0 commit comments