Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4a18323

Browse files
authored
Fix 3317 - don't apply line directives when analyzing files for editing (#3390)
* don't apply line directives when analyzing files for editing* add test
1 parentc6bf30e commit4a18323

File tree

5 files changed

+58
-8
lines changed

5 files changed

+58
-8
lines changed

‎src/fsharp/lex.fsl‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ rule token args skip = parse
520520
let line,file = parseLeadingDirective 1
521521

522522
// Construct the new position
523-
lexbuf.EndPos <- pos.ApplyLineDirective((match file with Some f -> fileIndexOfFile f | None -> pos.FileIndex), line)
523+
if args.applyLineDirectives then
524+
lexbuf.EndPos <- pos.ApplyLineDirective((match file with Some f -> fileIndexOfFile f | None -> pos.FileIndex), line)
524525

525526
token args skip lexbuf
526527
else

‎src/fsharp/lexhelp.fs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ type lexargs =
5555
ifdefStack:LexerIfdefStack
5656
resourceManager:LexResourceManager
5757
lightSyntaxStatus:LightSyntaxStatus
58-
errorLogger:ErrorLogger}
58+
errorLogger:ErrorLogger
59+
applyLineDirectives:bool}
5960

6061
/// possible results of lexing a long unicode escape sequence in a string literal, e.g. "\UDEADBEEF"
6162
typeLongUnicodeLexResult=
@@ -68,7 +69,8 @@ let mkLexargs (_filename,defines,lightSyntaxStatus,resourceManager,ifdefStack,er
6869
ifdefStack= ifdefStack
6970
lightSyntaxStatus=lightSyntaxStatus
7071
resourceManager=resourceManager
71-
errorLogger=errorLogger}
72+
errorLogger=errorLogger
73+
applyLineDirectives=true}
7274

7375
/// Register the lexbuf and call the given function
7476
letreusingLexbufForParsing lexbuf f=

‎src/fsharp/lexhelp.fsi‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ type LexResourceManager =
2828
new: unit-> LexResourceManager
2929

3030
typelexargs=
31-
{ defines:string list;
32-
ifdefStack:LexerIfdefStack;
33-
resourceManager:LexResourceManager;
34-
lightSyntaxStatus:LightSyntaxStatus;
35-
errorLogger:ErrorLogger}
31+
{ defines:string list
32+
ifdefStack:LexerIfdefStack
33+
resourceManager:LexResourceManager
34+
lightSyntaxStatus:LightSyntaxStatus
35+
errorLogger:ErrorLogger
36+
applyLineDirectives:bool}
3637

3738
typeLongUnicodeLexResult=
3839
| SurrogatePairofuint16*uint16

‎src/fsharp/vs/service.fs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,10 @@ module internal Parser =
14641464
lexResourceManager,
14651465
ref[],
14661466
errHandler.ErrorLogger)
1467+
1468+
// When analyzing files using ParseOneFile, i.e. for the use of editing clients, we do not apply line directives.
1469+
letlexargs={ lexargswith applyLineDirectives=false}
1470+
14671471
Lexhelp.usingLexbufForParsing(lexbuf, mainInputFileName)(fun lexbuf->
14681472
try
14691473
letskip=true

‎tests/service/ProjectAnalysisTests.fs‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5132,3 +5132,45 @@ let ``Test typed AST for struct unions`` () = // See https://github.com/fsharp/F
51325132
when uci.Name="Ok"&& obj.Equals(trueValue,true)&& obj.Equals(falseValue,false)->true
51335133
|_-> failwith"unexpected expression"
51345134
|> shouldEqualtrue
5135+
5136+
moduleinternalProjectLineDirectives=
5137+
openSystem.IO
5138+
5139+
letfileName1= Path.ChangeExtension(Path.GetTempFileName(),".fs")
5140+
letbase2= Path.GetTempFileName()
5141+
letdllName= Path.ChangeExtension(base2,".dll")
5142+
letprojFileName= Path.ChangeExtension(base2,".fsproj")
5143+
letfileSource1="""
5144+
module M
5145+
5146+
# 10 "Test.fsy"
5147+
let x = (1 = 3.0)
5148+
"""
5149+
5150+
File.WriteAllText(fileName1, fileSource1)
5151+
letfileNames=[fileName1]
5152+
letargs= mkProjectCommandLineArgs(dllName, fileNames)
5153+
letoptions= checker.GetProjectOptionsFromCommandLineArgs(projFileName, args)
5154+
5155+
[<Test>]
5156+
let``Test line directives in foreground analysis``()=// see https://github.com/Microsoft/visualfsharp/issues/3317
5157+
5158+
// In background analysis and normal compiler checking, the errors are reported w.r.t. the line directives
5159+
letwholeProjectResults= checker.ParseAndCheckProject(ProjectLineDirectives.options)|> Async.RunSynchronously
5160+
for ein wholeProjectResults.Errorsdo
5161+
printfn"ProjectLineDirectives wholeProjectResults error file: <<<%s>>>" e.FileName
5162+
5163+
[for ein wholeProjectResults.Errors-> e.StartLineAlternate, e.EndLineAlternate, e.FileName]|> shouldEqual[(10,10,"Test.fsy")]
5164+
5165+
// In foreground analysis routines, used by visual editing tools, the errors are reported w.r.t. the source
5166+
// file, which is assumed to be in the editor, not the other files referred to by line directives.
5167+
letcheckResults1=
5168+
checker.ParseAndCheckFileInProject(ProjectLineDirectives.fileName1,0, ProjectLineDirectives.fileSource1, ProjectLineDirectives.options)
5169+
|> Async.RunSynchronously
5170+
|>function(_,FSharpCheckFileAnswer.Succeeded x)-> x|_-> failwith"unexpected aborted"
5171+
5172+
for ein checkResults1.Errorsdo
5173+
printfn"ProjectLineDirectives checkResults1 error file: <<<%s>>>" e.FileName
5174+
5175+
[for ein checkResults1.Errors-> e.StartLineAlternate, e.EndLineAlternate, e.FileName]|> shouldEqual[(4,4, ProjectLineDirectives.fileName1)]
5176+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp