-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
ReSharper.FSharp/src/FSharp.Psi.Intentions/src/Intentions/GenerateSignatureFileAction.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |