Skip to content

Commit

Permalink
Raw outline of feature proposal.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jul 5, 2022
1 parent 4c6e9bc commit 770ab1f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<Compile Include="src\Intentions\SetNameAction.fs" />
<Compile Include="src\Intentions\LetToUseAction.fs" />
<Compile Include="src\Intentions\RenameFileToMatchTypeNameAction.fs" />
<Compile Include="src\Intentions\GenerateSignatureFileAction.fs" />
<Compile Include="src\QuickFixes\FSharpQuickFixBase.fs" />
<Compile Include="src\QuickFixes\RemoveUnusedOpensFix.fs" />
<Compile Include="src\QuickFixes\ReplaceUseWithLetFix.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace JetBrains.ReSharper.Plugins.FSharp.Psi.Features.ContextActions

open System.IO
open JetBrains.Application.UI.ActionsRevised.Menu
open JetBrains.ReSharper.Plugins.FSharp.Psi.Features.Intentions

type GenerateSignatureFileAction(dataProvider: FSharpContextActionDataProvider) =
interface IExecutableAction with
member this.Update(context, presentation, nextUpdate) =
let sourceFile = dataProvider.SourceFile.Name
let fsiFile = Path.ChangeExtension(sourceFile, ".fsi")
not (File.Exists fsiFile)

member this.Execute(context, nextExecute) =
let sourceFile = dataProvider.SourceFile.Name
let fsiFile = Path.ChangeExtension(sourceFile, ".fsi")
let currentFSharpFile = dataProvider.PsiFile
let fcsService = currentFSharpFile.FcsCheckerService
let checkResult = fcsService.ParseAndCheckFile(currentFSharpFile.GetSourceFile(), "for signature file", true)
match checkResult with
| None -> ()
| Some { CheckResults = checkResult } ->

match checkResult.GenerateSignature() with
| None -> ()
| Some signatureSourceText ->
let content = string signatureSourceText
File.WriteAllText(fsiFile, content)

0 comments on commit 770ab1f

Please sign in to comment.