Skip to content

Commit

Permalink
Simplify language service by reducing duplicate funcionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
7sharp9 committed Mar 2, 2015
1 parent 48de31c commit 89b6765
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
32 changes: 14 additions & 18 deletions FSharp.CompilerBinding/LanguageService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ type LanguageService(dirtyNotify) =
| Some (untyped,typed,_) when typed.HasFullTypeCheckInfo -> Some (ParseAndCheckResults(typed, untyped))
| _ -> None

member x.GetTypedParseResultWithTimeout(projectFilename, fileName:string, src, files, args, stale, timeout) =
member x.GetTypedParseResultWithTimeout(projectFilename, fileName:string, src, files, args, stale, ?timeout) =
async {
let fileName = if Path.GetExtension fileName = ".sketchfs" then Path.ChangeExtension (fileName, ".fsx") else fileName
let opts = x.GetCheckerOptions(fileName, projectFilename, src, files, args)
Expand All @@ -390,15 +390,9 @@ type LanguageService(dirtyNotify) =
| None ->
Debug.WriteLine(sprintf "LanguageService: Not using stale results - trying typecheck with timeout")
// If we didn't get a recent set of type checking results, we put in a request and wait for at most 'timeout' for a response
return mbox.TryPostAndReply((fun reply -> (fileName, src, opts, reply)), timeout = timeout)
}
member x.GetTypedParseResultAsync(projectFilename, fileName:string, src, files, args, stale) =
async {
let opts = x.GetCheckerOptions(fileName, projectFilename, src, files, args)

match x.TryGetStaleTypedParseResult(fileName, opts, src, stale) with
| Some results -> return results
| None -> return! mbox.PostAndAsyncReply(fun reply -> (fileName, src, opts, reply))
match timeout with
| Some timeout -> return mbox.TryPostAndReply((fun reply -> (fileName, src, opts, reply)), timeout = timeout)
| None -> return mbox.TryPostAndReply((fun reply -> (fileName, src, opts, reply)))
}

member x.GetTypedParseResultIfAvailable(projectFilename, fileName:string, src, files, args, stale) =
Expand All @@ -413,14 +407,16 @@ type LanguageService(dirtyNotify) =
async {
match FSharp.CompilerBinding.Parsing.findLongIdents(col, lineStr) with
| Some(colu, identIsland) ->

let! checkResults = x.GetTypedParseResultAsync(projectFilename, fileName, source, files, args, stale= AllowStaleResults.MatchingSource)
let! symbolResults = checkResults.GetSymbolAtLocation(line, colu, lineStr, identIsland)
match symbolResults with
| Some symbolUse ->
let lastIdent = Seq.last identIsland
let! refs = checkResults.GetUsesOfSymbolInFile(symbolUse.Symbol)
return Some(lastIdent, refs)
let! checkResults = x.GetTypedParseResultWithTimeout(projectFilename, fileName, source, files, args, stale= AllowStaleResults.MatchingSource)
match checkResults with
| Some results ->
let! symbolResults = results.GetSymbolAtLocation(line, colu, lineStr, identIsland)
match symbolResults with
| Some symbolUse ->
let lastIdent = Seq.last identIsland
let! refs = results.GetUsesOfSymbolInFile(symbolUse.Symbol)
return Some(lastIdent, refs)
| None -> return None
| None -> return None
| None -> return None
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type FSharpResolverProvider() =

let results =
asyncMaybe {
let! tyRes = MDLanguageService.Instance.GetTypedParseResultAsync (projFile, doc.FileName.FullPath.ToString(), docText, files, args, AllowStaleResults.MatchingSource) |> AsyncMaybe.liftAsync
let! tyRes = MDLanguageService.Instance.GetTypedParseResultWithTimeout (projFile, doc.FileName.FullPath.ToString(), docText, files, args, AllowStaleResults.MatchingSource)
LoggingService.LogInfo "ResolverProvider: Getting declaration location"
// Get the declaration location from the language service
let line, col, lineStr = MonoDevelop.getLineInfoFromOffset(offset, doc.Editor.Document)
Expand Down

0 comments on commit 89b6765

Please sign in to comment.