未验证 提交 be8154a8 编写于 作者: V Vlad Zarytovskii 提交者: GitHub

Use new IFSharpIndentationService (#13071)

上级 48fd60af
......@@ -9,6 +9,7 @@ open System.Threading
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Editor
open Microsoft.CodeAnalysis.Formatting
open Microsoft.CodeAnalysis.Host
open Microsoft.CodeAnalysis.Host.Mef
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor
......@@ -18,7 +19,7 @@ open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.EditorServices
open FSharp.Compiler.Tokenization
[<Export(typeof<IFSharpSynchronousIndentationService>)>]
[<Export(typeof<IFSharpIndentationService>)>]
type internal FSharpIndentationService
[<ImportingConstructor>]
() =
......@@ -90,18 +91,11 @@ type internal FSharpIndentationService
lastIndent
}
interface IFSharpSynchronousIndentationService with
member this.GetDesiredIndentation(document: Document, lineNumber: int, cancellationToken: CancellationToken): Nullable<FSharpIndentationResult> =
async {
let! cancellationToken = Async.CancellationToken
let! sourceText = document.GetTextAsync(cancellationToken) |> Async.AwaitTask
let! options = document.GetOptionsAsync(cancellationToken) |> Async.AwaitTask
let tabSize = options.GetOption<int>(FormattingOptions.TabSize, FSharpConstants.FSharpLanguageName)
let indentStyle = options.GetOption(FormattingOptions.SmartIndent, FSharpConstants.FSharpLanguageName)
let parsingOptions = document.GetFSharpQuickParsingOptions()
let indent = FSharpIndentationService.GetDesiredIndentation(document.Id, sourceText, document.FilePath, lineNumber, tabSize, indentStyle, parsingOptions)
return
interface IFSharpIndentationService with
member this.GetDesiredIndentation(services: HostLanguageServices, text: SourceText, documentId: DocumentId, path: string, lineNumber: int, options: FSharpIndentationOptions): Nullable<FSharpIndentationResult> =
let workspaceService = services.WorkspaceServices.GetRequiredService<IFSharpWorkspaceService>()
let parsingOptions = workspaceService.FSharpProjectOptionsManager.TryGetQuickParsingOptionsForEditingDocumentOrProject(documentId, path)
let indent = FSharpIndentationService.GetDesiredIndentation(documentId, text, path, lineNumber, options.TabSize, options.IndentStyle, parsingOptions)
match indent with
| None -> Nullable()
| Some(indentation) -> Nullable<FSharpIndentationResult>(FSharpIndentationResult(sourceText.Lines.[lineNumber].Start, indentation))
} |> (fun c -> Async.RunImmediateExceptOnUI(c,cancellationToken=cancellationToken))
| Some(indentation) -> Nullable<FSharpIndentationResult>(FSharpIndentationResult(text.Lines.[lineNumber].Start, indentation))
......@@ -526,10 +526,10 @@ type internal FSharpProjectOptionsManager
/// Get the options for a document or project relevant for syntax processing.
/// Quicker it doesn't need to recompute the exact project options for a script.
member _.TryGetQuickParsingOptionsForEditingDocumentOrProject(document:Document) =
match reactor.TryGetCachedOptionsByProjectId(document.Project.Id) with
member this.TryGetQuickParsingOptionsForEditingDocumentOrProject(documentId: DocumentId, path: string) =
match reactor.TryGetCachedOptionsByProjectId(documentId.ProjectId) with
| Some (_, parsingOptions, _) -> parsingOptions
| _ -> { FSharpParsingOptions.Default with IsInteractive = CompilerEnvironment.IsScriptFile document.Name }
| _ -> { FSharpParsingOptions.Default with IsInteractive = CompilerEnvironment.IsScriptFile path }
member _.SetCommandLineOptions(projectId, sourcePaths, options: ImmutableArray<string>) =
reactor.SetCommandLineOptions(projectId, sourcePaths, options.ToArray())
......
......@@ -144,7 +144,7 @@ type Document with
/// This tries to get the FSharpParsingOptions by looking at an internal cache; if it doesn't exist in the cache it will create an inaccurate but usable form of the FSharpParsingOptions.
member this.GetFSharpQuickParsingOptions() =
let workspaceService = this.Project.Solution.GetFSharpWorkspaceService()
workspaceService.FSharpProjectOptionsManager.TryGetQuickParsingOptionsForEditingDocumentOrProject(this)
workspaceService.FSharpProjectOptionsManager.TryGetQuickParsingOptionsForEditingDocumentOrProject(this.Id, this.FilePath)
/// A non-async call that quickly gets the defines of the given F# document.
/// This tries to get the defines by looking at an internal cache; if it doesn't exist in the cache it will create an inaccurate but usable form of the defines.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册