Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate signature file #378

Draft
wants to merge 3 commits into
base: net232
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Raw outline of feature proposal.
nojaf committed Feb 13, 2023
commit f6eecaacd94d6d0b943d11a750e57a95c3fda6ce
Original file line number Diff line number Diff line change
@@ -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" />
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)