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

Use ISourceText for file contents instead of string[] #777

Merged
merged 2 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 15 additions & 10 deletions src/FsAutoComplete.BackgroundServices/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ open FsAutoComplete
open Ionide.ProjInfo.ProjectSystem
open FSharp.UMX
open System.Reactive.Linq
open FSharp.Compiler.Text

type BackgroundFileCheckType =
| SourceFile of filePath: string
| ScriptFile of filePath: string * tfm: FSIRefs.TFM
Expand Down Expand Up @@ -146,21 +148,21 @@ type BackgroundServiceServer(state: State, client: FsacClient) =
let finalOpts = Array.append okOtherOpts (Array.ofList refs)
{ projOptions with OtherOptions = finalOpts }

let getScriptOptions file lines tfm =
let getScriptOptions file text tfm =
match tfm with
| FSIRefs.NetFx ->
checker.GetProjectOptionsFromScript(file, SourceText.ofString lines, assumeDotNetFramework = true, useSdkRefs = false, useFsiAuxLib = true)
checker.GetProjectOptionsFromScript(file, text, assumeDotNetFramework = true, useSdkRefs = false, useFsiAuxLib = true)
| FSIRefs.NetCore ->
async {
let! (opts, errors) = checker.GetProjectOptionsFromScript(file, SourceText.ofString lines, assumeDotNetFramework = false, useSdkRefs = true, useFsiAuxLib = true)
let! (opts, errors) = checker.GetProjectOptionsFromScript(file, text, assumeDotNetFramework = false, useSdkRefs = true, useFsiAuxLib = true)
return replaceRefs opts, errors
}

match file with
| ScriptFile(file, tfm) ->
state.Files.TryFind (Utils.normalizePath file) |> Option.map (fun st ->
async {
let! (opts, _errors) = getScriptOptions file (st.Lines |> String.concat "\n") tfm
let! (opts, _errors) = getScriptOptions file st.Lines tfm
let sf = getFilesFromOpts opts

return
Expand Down Expand Up @@ -189,8 +191,8 @@ type BackgroundServiceServer(state: State, client: FsacClient) =
do! client.Notify {Value = sprintf "Typechecking %s" (UMX.untag file) }
match state.Files.TryFind file, state.FileCheckOptions.TryFind file with
| Some vf, Some opts ->
let txt = vf.Lines |> String.concat "\n"
let! pr, cr = checker.ParseAndCheckFileInProject(UMX.untag file, defaultArg vf.Version 0, SourceText.ofString txt, opts)
let txt = vf.Lines
let! pr, cr = checker.ParseAndCheckFileInProject(UMX.untag file, defaultArg vf.Version 0, txt, opts)
match cr with
| FSharpCheckFileAnswer.Aborted ->
do! client.Notify {Value = sprintf "Typechecking aborted %s" (UMX.untag file) }
Expand All @@ -206,9 +208,9 @@ type BackgroundServiceServer(state: State, client: FsacClient) =
do! client.SendDiagnostics msg
return ()
| Some vf, None when (UMX.untag file).EndsWith ".fsx" ->
let txt = vf.Lines |> String.concat "\n"
let! (opts, _errors) = checker.GetProjectOptionsFromScript(UMX.untag file, SourceText.ofString txt, assumeDotNetFramework = true, useSdkRefs = false)
let! pr, cr = checker.ParseAndCheckFileInProject(UMX.untag file, defaultArg vf.Version 0, SourceText.ofString txt, opts)
let txt = vf.Lines
let! (opts, _errors) = checker.GetProjectOptionsFromScript(UMX.untag file, txt, assumeDotNetFramework = true, useSdkRefs = false)
let! pr, cr = checker.ParseAndCheckFileInProject(UMX.untag file, defaultArg vf.Version 0, txt, opts)
match cr with
| FSharpCheckFileAnswer.Aborted ->
do! client.Notify {Value = sprintf "Typechecking aborted %s" (UMX.untag file) }
Expand Down Expand Up @@ -326,7 +328,10 @@ type BackgroundServiceServer(state: State, client: FsacClient) =
do! client.Notify {Value = sprintf "File update %s" p.File.FilePath }
let file = Utils.normalizePath p.File.FilePath

let vf = {Lines = p.Content.Split( [|'\n' |] ); Touched = DateTime.Now; Version = Some p.Version }
let vf =
{ Lines = SourceText.ofString p.Content
Touched = DateTime.Now
Version = Some p.Version }
state.Files.AddOrUpdate(file, (fun _ -> vf),( fun _ _ -> vf) ) |> ignore
let! filesToCheck = defaultArg (getListOfFilesForProjectChecking p.File) (async.Return [])
do! client.Notify { Value = sprintf "Files to check %A" filesToCheck }
Expand Down
6 changes: 3 additions & 3 deletions src/FsAutoComplete.Core/AbstractClassStubGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ let getMemberNameAndRanges (abstractClassData) =
| AbstractClassData.ObjExpr (_, bindings, _) -> List.choose (|MemberNameAndRange|_|) bindings

/// Try to find the start column, so we know what the base indentation should be
let inferStartColumn (codeGenServer : CodeGenerationService) (pos : Pos) (doc : Document) (lines: LineStr[]) (lineStr : string) (abstractClassData : AbstractClassData) (indentSize : int) =
let inferStartColumn (codeGenServer : CodeGenerationService) (pos : Pos) (doc : Document) (lines: ISourceText) (lineStr : string) (abstractClassData : AbstractClassData) (indentSize : int) =
match getMemberNameAndRanges abstractClassData with
| (_, range) :: _ ->
getLineIdent lines.[range.StartLine-1]
getLineIdent (lines.GetLineString(range.StartLine - 1))
| [] ->
match abstractClassData with
| AbstractClassData.ExplicitImpl _ ->
Expand All @@ -122,7 +122,7 @@ let inferStartColumn (codeGenServer : CodeGenerationService) (pos : Pos) (doc :
/// Try to write any missing members of the given abstract type at the given location.
/// If the destination type isn't an abstract class, or if there are no missing members to implement,
/// nothing is written. Otherwise, a list of missing members is generated and written
let writeAbstractClassStub (codeGenServer : CodeGenerationService) (checkResultForFile: ParseAndCheckResults) (doc : Document) (lines: LineStr[]) (lineStr : string) (abstractClassData : AbstractClassData) =
let writeAbstractClassStub (codeGenServer : CodeGenerationService) (checkResultForFile: ParseAndCheckResults) (doc : Document) (lines: ISourceText) (lineStr : string) (abstractClassData : AbstractClassData) =
asyncMaybe {
let pos = Pos.mkPos abstractClassData.AbstractTypeIdentRange.Start.Line (abstractClassData.AbstractTypeIdentRange.End.Column)
let! (_lexerSym, usages) = codeGenServer.GetSymbolAndUseAtPositionOfKind(doc.FullName, pos, SymbolKind.Ident)
Expand Down
4 changes: 2 additions & 2 deletions src/FsAutoComplete.Core/CodeGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ type CodeGenerationService(checker : FSharpCompilerServiceChecker, state : State
member x.TokenizeLine(fileName, i) =
match state.TryGetFileCheckerOptionsWithLines fileName with
| ResultOrString.Error _ -> None
| ResultOrString.Ok (opts, lines) ->
| ResultOrString.Ok (opts, text) ->
try
let line = lines.[ i - 1 ]
let line = text.GetLineString (i - 1)
Lexer.tokenizeLine [||] line |> Some
with
| _ -> None
Expand Down
Loading