-
Notifications
You must be signed in to change notification settings - Fork 153
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
Refactor Symbol Cache #384
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -9,6 +9,88 @@ open System.Net | |
open System.IO | ||
open Newtonsoft.Json | ||
|
||
[<CLIMutable>] | ||
type SymbolUseRange = { | ||
FileName: string | ||
StartLine: int | ||
StartColumn: int | ||
EndLine: int | ||
EndColumn: int | ||
IsFromDefinition: bool | ||
IsFromAttribute : bool | ||
IsFromComputationExpression : bool | ||
IsFromDispatchSlotImplementation : bool | ||
IsFromPattern : bool | ||
IsFromType : bool | ||
SymbolFullName: string | ||
SymbolDisplayName: string | ||
SymbolIsLocal: bool | ||
} | ||
|
||
|
||
module PersistenCacheImpl = | ||
open Microsoft.Data.Sqlite | ||
open Dapper | ||
open System.Data | ||
|
||
let mutable connection : SqliteConnection option = None | ||
|
||
let insert (connection: SqliteConnection) file (sugs: SymbolUseRange[]) = | ||
if connection.State <> ConnectionState.Open then connection.Open() | ||
use tx = connection.BeginTransaction() | ||
let delCmd = sprintf "DELETE FROM Symbols WHERE FileName=\"%s\"" file | ||
let inserCmd = | ||
sprintf "INSERT INTO SYMBOLS(FileName, StartLine, StartColumn, EndLine, EndColumn, IsFromDefinition, IsFromAttribute, IsFromComputationExpression, IsFromDispatchSlotImplementation, IsFromPattern, IsFromType, SymbolFullName, SymbolDisplayName, SymbolIsLocal) VALUES | ||
(@FileName, @StartLine, @StartColumn, @EndLine, @EndColumn, @IsFromDefinition, @IsFromAttribute, @IsFromComputationExpression, @IsFromDispatchSlotImplementation, @IsFromPattern, @IsFromType, @SymbolFullName, @SymbolDisplayName, @SymbolIsLocal)" | ||
connection.Execute(delCmd, transaction = tx) |> ignore | ||
connection.Execute(inserCmd, sugs, transaction = tx) |> ignore | ||
tx.Commit() | ||
|
||
let loadAll (connection: SqliteConnection) = | ||
if connection.State <> ConnectionState.Open then connection.Open() | ||
let q = "SELECT * FROM SYMBOLS" | ||
let res = connection.Query<SymbolUseRange>(q) | ||
res | ||
|
||
let loadFile (connection: SqliteConnection) file = | ||
if connection.State <> ConnectionState.Open then connection.Open() | ||
let q = sprintf "SELECT * FROM SYMBOLS WHERE FileName=\"%s\"" file | ||
let res = connection.Query<SymbolUseRange>(q) | ||
res | ||
|
||
let initializeCache dir = | ||
let connectionString = sprintf "Data Source=%s/.ionide/symbolCache.db" dir | ||
|
||
let dir = Path.Combine(dir, ".ionide") | ||
do if not (Directory.Exists dir) then Directory.CreateDirectory dir |> ignore | ||
let dbPath = Path.Combine(dir, "symbolCache.db") | ||
let dbExists = File.Exists dbPath | ||
let connection = new SqliteConnection(connectionString) | ||
|
||
do if not dbExists then | ||
let fs = File.Create(dbPath) | ||
fs.Close() | ||
let cmd = "CREATE TABLE Symbols( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesnt work if the schema will be updated later to v2. |
||
FileName TEXT, | ||
StartLine INT, | ||
StartColumn INT, | ||
EndLine INT, | ||
EndColumn INT, | ||
IsFromDefinition BOOLEAN, | ||
IsFromAttribute BOOLEAN, | ||
IsFromComputationExpression BOOLEAN, | ||
IsFromDispatchSlotImplementation BOOLEAN, | ||
IsFromPattern BOOLEAN, | ||
IsFromType BOOLEAN, | ||
SymbolFullName TEXT, | ||
SymbolDisplayName TEXT, | ||
SymbolIsLocal BOOLEAN | ||
)" | ||
|
||
connection.Execute(cmd) | ||
|> ignore | ||
connection | ||
|
||
let makePostRequest (url : string) (requestBody : string) = | ||
let req = WebRequest.CreateHttp url | ||
req.CookieContainer <- new CookieContainer() | ||
|
@@ -30,28 +112,11 @@ let makePostRequest (url : string) (requestBody : string) = | |
|
||
let mutable port = 0 | ||
|
||
[<CLIMutable>] | ||
type SymbolUseRange = { | ||
FileName: string | ||
StartLine: int | ||
StartColumn: int | ||
EndLine: int | ||
EndColumn: int | ||
IsFromDefinition: bool | ||
IsFromAttribute : bool | ||
IsFromComputationExpression : bool | ||
IsFromDispatchSlotImplementation : bool | ||
IsFromPattern : bool | ||
IsFromType : bool | ||
SymbolFullName: string | ||
SymbolDisplayName: string | ||
SymbolIsLocal: bool | ||
} | ||
|
||
type SymbolCacheRequest = { | ||
Filename: string | ||
Uses: SymbolUseRange[] | ||
} | ||
|
||
let p = | ||
let t = typeof<SymbolCacheRequest> | ||
Path.GetDirectoryName t.Assembly.Location | ||
|
@@ -62,6 +127,7 @@ let pid = | |
|
||
let startCache (dir : string) = | ||
port <- Random().Next(9000,9999) | ||
PersistenCacheImpl.connection <- Some (PersistenCacheImpl.initializeCache dir) | ||
let si = ProcessStartInfo() | ||
si.RedirectStandardOutput <- true | ||
si.RedirectStandardError <- true | ||
|
@@ -105,11 +171,14 @@ let fromSymbolUse (su : FSharpSymbolUse) = | |
|
||
|
||
let sendSymbols (serializer: Serializer) fn (symbols: FSharpSymbolUse[]) = | ||
let request = | ||
let sus = | ||
symbols | ||
|> Array.map(fromSymbolUse) | ||
|> fun n -> {Filename = fn; Uses = n} | ||
|> serializer | ||
|
||
PersistenCacheImpl.connection | ||
|> Option.iter (fun con -> PersistenCacheImpl.insert con fn sus ) | ||
|
||
let request = serializer {Filename = fn} | ||
|
||
try | ||
makePostRequest ("http://localhost:" + (string port) + "/updateSymbols") request | ||
|
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 |
---|---|---|
|
@@ -9,3 +9,5 @@ ICSharpCode.Decompiler | |
FSharp.Analyzers.SDK | ||
Microsoft.SourceLink.GitHub | ||
FSharp.Data | ||
Dapper | ||
Microsoft.Data.Sqlite |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we use
/.ionide/obj
, that will be git ignored by default by pratically all.gitignores
, so less noiseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is that it's passed as argument to FSAC.
So editors can put that: