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

Commit8f6315c

Browse files
TIHanbrettfo
authored andcommitted
Dev16 is partially working
1 parent8551c4c commit8f6315c

File tree

4 files changed

+186
-26
lines changed

4 files changed

+186
-26
lines changed

‎vsintegration/src/FSharp.Editor/Diagnostics/UnusedDeclarationsAnalyzer.fs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ type internal UnusedDeclarationsAnalyzer() =
106106

107107
do Trace.TraceInformation("{0:n3} (start) UnusedDeclarationsAnalyzer", DateTime.Now.TimeOfDay.TotalSeconds)
108108
do! Async.Sleep DefaultTuning.UnusedDeclarationsAnalyzerInitialDelay|> liftAsync// be less intrusive, give other work priority most of the time
109-
match getProjectInfoManager(document).TryGetOptionsForEditingDocumentOrProject(document)with
110-
|Some(_parsingOptions, projectOptions)->
109+
match! getProjectInfoManager(document).TryGetOptionsForEditingDocumentOrProject(document)with
110+
|(_parsingOptions, projectOptions)->
111111
let!sourceText= document.GetTextAsync()
112112
letchecker= getChecker document
113113
let!_,_,checkResults= checker.ParseAndCheckDocument(document, projectOptions, sourceText= sourceText, userOpName= userOpName)
@@ -117,7 +117,6 @@ type internal UnusedDeclarationsAnalyzer() =
117117
unusedRanges
118118
|> Seq.map(fun m-> Diagnostic.Create(Descriptor, RoslynHelpers.RangeToLocation(m, sourceText, document.FilePath)))
119119
|> Seq.toImmutableArray
120-
| None->return ImmutableArray.Empty
121120
}
122121
|> Async.map(Option.defaultValue ImmutableArray.Empty)
123122
|> RoslynHelpers.StartAsyncAsTask cancellationToken

‎vsintegration/src/FSharp.Editor/Formatting/EditorFormattingService.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ type internal FSharpEditorFormattingService
151151
let!sourceText= document.GetTextAsync(cancellationToken)|> Async.AwaitTask
152152
let!options= document.GetOptionsAsync(cancellationToken)|> Async.AwaitTask
153153
letindentStyle= options.GetOption(FormattingOptions.SmartIndent, FSharpConstants.FSharpLanguageName)
154-
letprojectOptionsOpt= projectInfoManager.TryGetOptionsForEditingDocumentOrProject document
154+
let!projectOptionsOpt= projectInfoManager.TryGetOptionsForEditingDocumentOrProject document
155155
let!textChange= FSharpEditorFormattingService.GetFormattingChanges(document.Id, sourceText, document.FilePath, checkerProvider.Checker, indentStyle, projectOptionsOpt, position)
156156
return textChange|> Option.toList|> toIList
157157
}
@@ -162,7 +162,7 @@ type internal FSharpEditorFormattingService
162162
let!options= document.GetOptionsAsync(cancellationToken)|> Async.AwaitTask
163163
lettabSize= options.GetOption<int>(FormattingOptions.TabSize, FSharpConstants.FSharpLanguageName)
164164

165-
match projectInfoManager.TryGetOptionsForEditingDocumentOrProject documentwith
165+
match! projectInfoManager.TryGetOptionsForEditingDocumentOrProject documentwith
166166
| Some(parsingOptions,_)->
167167
let!textChanges= FSharpEditorFormattingService.GetPasteChanges(document.Id, sourceText, document.FilePath, settings.Formatting, tabSize, parsingOptions, currentClipboard, span)
168168
return textChanges|> Option.defaultValue Seq.empty|> toIList

‎vsintegration/src/FSharp.Editor/Formatting/IndentationService.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type internal FSharpIndentationService
100100
let!options= document.GetOptionsAsync(cancellationToken)|> Async.AwaitTask
101101
lettabSize= options.GetOption<int>(FormattingOptions.TabSize, FSharpConstants.FSharpLanguageName)
102102
letindentStyle= options.GetOption(FormattingOptions.SmartIndent, FSharpConstants.FSharpLanguageName)
103-
letprojectOptionsOpt= projectInfoManager.TryGetOptionsForEditingDocumentOrProject document
103+
let!projectOptionsOpt= projectInfoManager.TryGetOptionsForEditingDocumentOrProject document
104104
letindent= FSharpIndentationService.GetDesiredIndentation(document.Id, sourceText, document.FilePath, lineNumber, tabSize, indentStyle, projectOptionsOpt)
105105
return
106106
match indentwith

‎vsintegration/src/FSharp.Editor/LanguageService/FSharpProjectOptionsManager.fs‎

Lines changed: 181 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespaceMicrosoft.VisualStudio.FSharp.Editor
44

55
openSystem
6+
openSystem.Collections.Generic
67
openSystem.Collections.Concurrent
78
openSystem.Collections.Immutable
89
openSystem.ComponentModel.Composition
@@ -17,6 +18,170 @@ open Microsoft.VisualStudio.FSharp.Editor.SiteProvider
1718
openMicrosoft.VisualStudio.LanguageServices
1819
openMicrosoft.VisualStudio.LanguageServices.Implementation.ProjectSystem
1920
openMicrosoft.VisualStudio.Shell
21+
openSystem.Threading
22+
openMicrosoft.VisualStudio.Shell.Interop
23+
openMicrosoft.VisualStudio.LanguageServices.Implementation.TaskList
24+
25+
[<AutoOpen>]
26+
moduleprivateFSharpProjectOptionsHelpers=
27+
28+
letmapProjectToSite(workspace:VisualStudioWorkspaceImpl,project:Project,serviceProvider:System.IServiceProvider,projectOptionsTable:FSharpProjectOptionsTable option)=
29+
lethier= workspace.GetHierarchy(project.Id)
30+
letgetCommandLineOptionsWithProjectId(projectId)=
31+
match projectOptionsTablewith
32+
| Some(options)-> options.GetCommandLineOptionsWithProjectId(projectId)
33+
| None->[||],[||],[||]
34+
{
35+
new IProvideProjectSitewith
36+
memberx.GetProjectSite()=
37+
letfst(a,_,_)= a
38+
letsnd(_,b,_)= b
39+
let mutableerrorReporter=
40+
letreporter= ProjectExternalErrorReporter(project.Id,"FS", serviceProvider)
41+
Some(reporter:> IVsLanguageServiceBuildErrorReporter2)
42+
43+
{
44+
new IProjectSitewith
45+
member__.Description= project.Name
46+
member__.CompilationSourceFiles= getCommandLineOptionsWithProjectId(project.Id)|> fst
47+
member__.CompilationOptions=
48+
let_,references,options= getCommandLineOptionsWithProjectId(project.Id)
49+
Array.concat[options; references|> Array.map(fun r->"-r:"+ r)]
50+
member__.CompilationReferences= getCommandLineOptionsWithProjectId(project.Id)|> snd
51+
membersite.CompilationBinOutputPath= site.CompilationOptions|> Array.tryPick(fun s->if s.StartsWith("-o:")then Some s.[3..]else None)
52+
member__.ProjectFileName= project.FilePath
53+
member__.AdviseProjectSiteChanges(_,_)=()
54+
member__.AdviseProjectSiteCleaned(_,_)=()
55+
member__.AdviseProjectSiteClosed(_,_)=()
56+
member__.IsIncompleteTypeCheckEnvironment=false
57+
member__.TargetFrameworkMoniker=""
58+
member__.ProjectGuid= project.Id.Id.ToString()
59+
member__.LoadTime= System.DateTime.Now
60+
member__.ProjectProvider= Some(x)
61+
member__.BuildErrorReporterwith get()= errorReporterandset(v)= errorReporter<- v
62+
}
63+
interface IVsHierarchywith
64+
member__.SetSite(psp)= hier.SetSite(psp)
65+
member__.GetSite(psp)= hier.GetSite(ref psp)
66+
member__.QueryClose(pfCanClose)= hier.QueryClose(ref pfCanClose)
67+
member__.Close()= hier.Close()
68+
member__.GetGuidProperty(itemid,propid,pguid)= hier.GetGuidProperty(itemid, propid, ref pguid)
69+
member__.SetGuidProperty(itemid,propid,rguid)= hier.SetGuidProperty(itemid, propid, ref rguid)
70+
member__.GetProperty(itemid,propid,pvar)= hier.GetProperty(itemid, propid, ref pvar)
71+
member__.SetProperty(itemid,propid,var)= hier.SetProperty(itemid, propid, var)
72+
member__.GetNestedHierarchy(itemid,iidHierarchyNested,ppHierarchyNested,pitemidNested)=
73+
hier.GetNestedHierarchy(itemid, ref iidHierarchyNested, ref ppHierarchyNested, ref pitemidNested)
74+
member__.GetCanonicalName(itemid,pbstrName)= hier.GetCanonicalName(itemid, ref pbstrName)
75+
member__.ParseCanonicalName(pszName,pitemid)= hier.ParseCanonicalName(pszName, ref pitemid)
76+
member__.Unused0()= hier.Unused0()
77+
member__.AdviseHierarchyEvents(pEventSink,pdwCookie)= hier.AdviseHierarchyEvents(pEventSink, ref pdwCookie)
78+
member__.UnadviseHierarchyEvents(dwCookie)= hier.UnadviseHierarchyEvents(dwCookie)
79+
member__.Unused1()= hier.Unused1()
80+
member__.Unused2()= hier.Unused2()
81+
member__.Unused3()= hier.Unused3()
82+
member__.Unused4()= hier.Unused4()
83+
}
84+
85+
[<RequireQualifiedAccess>]
86+
typeprivateFSharpProjectOptionsMessage=
87+
| TryGetOptionsofProject*AsyncReplyChannel<(FSharpParsingOptions*FSharpProjectOptions)option>
88+
| ClearOptionsofProjectId
89+
90+
[<Sealed>]
91+
typeprivateFSharpProjectOptionsReactor(workspace: VisualStudioWorkspaceImpl,settings: EditorOptions,optionsTable: FSharpProjectOptionsTable,serviceProvider,checkerProvider: FSharpCheckerProvider)=
92+
letcancellationTokenSource=new CancellationTokenSource()
93+
94+
letcache= Dictionary<ProjectId, VersionStamp* FSharpParsingOptions* FSharpProjectOptions>()
95+
96+
let rectryComputeOptions(project:Project)=
97+
letprojectId= project.Id
98+
letprojectStamp= project.Version
99+
match cache.TryGetValue(projectId)with
100+
|false,_->
101+
102+
letreferencedProjects=
103+
if settings.LanguageServicePerformance.EnableInMemoryCrossProjectReferencesthen
104+
project.ProjectReferences
105+
|> Seq.choose(fun projectReference->
106+
letreferenceProject= project.Solution.GetProject(projectReference.ProjectId)
107+
tryComputeOptions referenceProject
108+
|> Option.map(fun(_,projectOptions)->
109+
(referenceProject.OutputFilePath, projectOptions)
110+
)
111+
)
112+
|> Seq.toArray
113+
else
114+
[||]
115+
116+
lethier= workspace.GetHierarchy(projectId)
117+
letprojectSite=
118+
match hierwith
119+
|(:? IProvideProjectSiteas provideSite)-> provideSite.GetProjectSite()
120+
|_->
121+
letprovideSite= mapProjectToSite(workspace, project, serviceProvider, Some(optionsTable))
122+
provideSite.GetProjectSite()
123+
124+
letprojectOptions=
125+
{
126+
ProjectFileName= projectSite.ProjectFileName
127+
ProjectId= None
128+
SourceFiles= projectSite.CompilationSourceFiles
129+
OtherOptions= projectSite.CompilationOptions
130+
ReferencedProjects= referencedProjects
131+
IsIncompleteTypeCheckEnvironment= projectSite.IsIncompleteTypeCheckEnvironment
132+
UseScriptResolutionRules= SourceFile.MustBeSingleFileProject(Path.GetFileName(project.FilePath))
133+
LoadTime= projectSite.LoadTime
134+
UnresolvedReferences= None
135+
OriginalLoadReferences=[]
136+
ExtraProjectInfo= None
137+
Stamp= Some(int64<| projectStamp.GetHashCode())
138+
}
139+
140+
if Array.isEmpty projectOptions.SourceFilesthen
141+
None
142+
else
143+
144+
checkerProvider.Checker.InvalidateConfiguration(projectOptions, startBackgroundCompileIfAlreadySeen=true, userOpName="computeOptions")
145+
146+
letparsingOptions,_= checkerProvider.Checker.GetParsingOptionsFromProjectOptions(projectOptions)
147+
148+
cache.[projectId]<-(projectStamp, parsingOptions, projectOptions)
149+
150+
Some(parsingOptions, projectOptions)
151+
152+
|true,(projectStamp2, parsingOptions, projectOptions)->
153+
if projectStamp<> projectStamp2then
154+
cache.Remove(projectId)|> ignore
155+
tryComputeOptions project
156+
else
157+
Some(parsingOptions, projectOptions)
158+
159+
letloop(agent:MailboxProcessor<FSharpProjectOptionsMessage>)=
160+
async{
161+
whiletruedo
162+
try
163+
match! agent.Receive()with
164+
| FSharpProjectOptionsMessage.TryGetOptions(project, reply)->
165+
reply.Reply(tryComputeOptions project)
166+
| FSharpProjectOptionsMessage.ClearOptions(projectId)->
167+
cache.Remove(projectId)|> ignore
168+
with
169+
|_->()
170+
}
171+
172+
letagent= MailboxProcessor.Start((fun agent-> loop agent), cancellationToken= cancellationTokenSource.Token)
173+
174+
member__.TryGetOptionsByProjectAsync(project)=
175+
agent.PostAndAsyncReply(fun reply-> FSharpProjectOptionsMessage.TryGetOptions(project, reply))
176+
177+
member__.ClearOptionsByProjectId(projectId)=
178+
agent.Post(FSharpProjectOptionsMessage.ClearOptions(projectId))
179+
180+
interface IDisposablewith
181+
member__.Dispose()=
182+
cancellationTokenSource.Cancel()
183+
cancellationTokenSource.Dispose()
184+
(agent:> IDisposable).Dispose()
20185

21186
/// Exposes FCS FSharpProjectOptions information management as MEF component.
22187
//
@@ -36,6 +201,8 @@ type internal FSharpProjectOptionsManager
36201
// A table of information about projects, excluding single-file projects.
37202
letprojectOptionsTable= FSharpProjectOptionsTable()
38203

204+
letreactor=new FSharpProjectOptionsReactor(workspace, settings, projectOptionsTable, serviceProvider, checkerProvider)
205+
39206
// A table of information about single-file projects. Currently we only need the load time of each such file, plus
40207
// the original options for editing
41208
letsingleFileProjectTable= ConcurrentDictionary<ProjectId, DateTime* FSharpParsingOptions* FSharpProjectOptions>()
@@ -48,7 +215,9 @@ type internal FSharpProjectOptionsManager
48215
member__.FSharpOptions= projectOptionsTable
49216

50217
/// Clear a project from the project table
51-
memberthis.ClearInfoForProject(projectId:ProjectId)= projectOptionsTable.ClearInfoForProject(projectId)
218+
memberthis.ClearInfoForProject(projectId:ProjectId)=
219+
projectOptionsTable.ClearInfoForProject(projectId)
220+
reactor.ClearOptionsByProjectId(projectId)
52221

53222
/// Clear a project from the single file project table
54223
memberthis.ClearInfoForSingleFileProject(projectId)=
@@ -129,31 +298,24 @@ type internal FSharpProjectOptionsManager
129298
Assert.Exception(ex)
130299
return None
131300
|_->
132-
match this.TryGetOptionsForProject(projectId)with
133-
| Some(parsingOptions, site, projectOptions)->
134-
letprojectOptions=
135-
{ projectOptionswith
136-
ReferencedProjects=
137-
document.Project.ProjectReferences
138-
|> Seq.choose(fun projectReference->
139-
letreferenceProject= document.Project.Solution.GetProject(projectReference.ProjectId)
140-
match this.TryGetOptionsForProject(projectReference.ProjectId)with
141-
| Some(_,_, referenceProjectOptions)-> Some(referenceProject.OutputFilePath, referenceProjectOptions)
142-
|_-> None
143-
)
144-
|> Seq.toArray
145-
}
146-
return Some(parsingOptions, site, projectOptions)
147-
|_->return None
301+
match! reactor.TryGetOptionsByProjectAsync(document.Project)with
302+
| Some(parsingOptions, projectOptions)->
303+
return Some(parsingOptions, None, projectOptions)
304+
|_->
305+
return None
148306
}
149307

150308
/// Get the options for a document or project relevant for syntax processing.
151309
/// Quicker then TryGetOptionsForDocumentOrProject as it doesn't need to recompute the exact project options for a script.
152310
memberthis.TryGetOptionsForEditingDocumentOrProject(document:Document)=
153311
letprojectId= document.Project.Id
154312
match singleFileProjectTable.TryGetValue(projectId)with
155-
|true,(_loadTime, parsingOptions, originalOptions)-> Some(parsingOptions, originalOptions)
156-
|_-> this.TryGetOptionsForProject(projectId)|> Option.map(fun(parsingOptions,_,projectOptions)-> parsingOptions, projectOptions)
313+
|true,(_loadTime, parsingOptions, originalOptions)->async{return Some(parsingOptions, originalOptions)}
314+
|_->
315+
async{
316+
let!result= this.TryGetOptionsForDocumentOrProject(document)
317+
return result|> Option.map(fun(parsingOptions,_,projectOptions)-> parsingOptions, projectOptions)
318+
}
157319

158320
/// get a siteprovider
159321
memberthis.ProvideProjectSiteProvider(project:Project)= provideProjectSiteProvider(workspace, project, serviceProvider, Some projectOptionsTable)
@@ -197,6 +359,5 @@ type internal FSharpProjectOptionsManager
197359
letreferencePaths= references|> Seq.map(fun r-> fullPath r.Reference)|> Seq.toArray
198360

199361
projectOptionsTable.SetOptionsWithProjectId(projectId, sourcePaths, referencePaths, options.ToArray())
200-
this.UpdateProjectInfoWithProjectId(projectId,"HandleCommandLineChanges", invalidateConfig=true, solution=workspace.CurrentSolution)
201362

202363
member__.Checker= checkerProvider.Checker

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp