Skip to content

Commit 59d515c

Browse files
TIHanbaronfel
authored andcommitted
Fixed line directive ranges when not applying a line directive (#7011)
* Fixed line directive ranges when not applying a line directive * Update ProjectAnalysisTests.fs
1 parent 1cf1a79 commit 59d515c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/fsharp/lex.fsl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,14 @@ rule token args skip = parse
524524
// Construct the new position
525525
if args.applyLineDirectives then
526526
lexbuf.EndPos <- pos.ApplyLineDirective((match file with Some f -> fileIndexOfFile f | None -> pos.FileIndex), line)
527-
527+
else
528+
// add a newline when we don't apply a directive since we consumed a newline getting here
529+
newline lexbuf
528530
token args skip lexbuf
529-
else
530-
if not skip then (HASH_LINE (LexCont.Token !args.ifdefStack)) else token args skip lexbuf }
531+
else
532+
// add a newline when we don't apply a directive since we consumed a newline getting here
533+
newline lexbuf
534+
(HASH_LINE (LexCont.Token !args.ifdefStack)) }
531535

532536
| "<@" { checkExprOp lexbuf; LQUOTE ("<@ @>", false) }
533537
| "<@@" { checkExprOp lexbuf; LQUOTE ("<@@ @@>", true) }

tests/service/ProjectAnalysisTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5291,7 +5291,7 @@ let ``Test line directives in foreground analysis`` () = // see https://github.c
52915291
for e in checkResults1.Errors do
52925292
printfn "ProjectLineDirectives checkResults1 error file: <<<%s>>>" e.FileName
52935293

5294-
[ for e in checkResults1.Errors -> e.StartLineAlternate, e.EndLineAlternate, e.FileName ] |> shouldEqual [(4, 4, ProjectLineDirectives.fileName1)]
5294+
[ for e in checkResults1.Errors -> e.StartLineAlternate, e.EndLineAlternate, e.FileName ] |> shouldEqual [(5, 5, ProjectLineDirectives.fileName1)]
52955295

52965296
//------------------------------------------------------
52975297

0 commit comments

Comments
 (0)