@@ -353,12 +353,28 @@ type Server(client: ILanguageClient,useCache:bool) =
353
353
/// Request that `uri` be checked when the user stops doing things for 1 second
354
354
let backgroundCheck = DebounceCheck( doCheck, 1000 )
355
355
let projectAssetsDebounce = DebounceCheck(( fun file -> async { projects.UpdateAssetsJson( file)}), 1000 )
356
+
357
+ ///Fixes problems with getting identifiers in DU's when the union is against a pipe. It add's a space
358
+ let fixLineForIdentifying line ( charPos : int )=
359
+ let mutable indicies : int list = List.empty
360
+ let newLine = Regex.Replace( line, " (\\ |)(?=\\ w)" , fun ( x : Match ) ->
361
+ indicies<- x.Index :: indicies
362
+ " | "
363
+ )
364
+
365
+ //Adds one to the position we are looking for, for each match before our pos because we add an extra space at those points
366
+ let newPos = indicies|> List.rev|> List.fold( fun cPos matchPos -> if cPos<= matchPos then cPos+ 1 else cPos ) charPos
367
+ newLine, newPos
368
+
356
369
/// Find the symbol at a position
357
370
let symbolAt ( textDocument : TextDocumentIdentifier , position : Position ): Async < FSharpSymbolUse option > =
358
371
async {
359
372
let file = normedFileInfo( textDocument.uri.LocalPath)
360
373
let! c = checkOpenFile( file, true , false )
361
374
let line = lineContent( file, position.line)
375
+
376
+ let line , charPos = fixLineForIdentifying line position.character
377
+
362
378
let maybeId = QuickParse.GetCompleteIdentifierIsland false line ( position.character)
363
379
match c, maybeId with
364
380
| Error( errors), _ ->
@@ -679,19 +695,23 @@ type Server(client: ILanguageClient,useCache:bool) =
679
695
let file = normedFileInfo( p.textDocument.uri.LocalPath)
680
696
let! c = checkOpenFile( file, true , false )
681
697
let line = lineContent( file, p.position.line)
682
- let maybeId = QuickParse.GetCompleteIdentifierIsland false line ( p.position.character)
698
+
699
+ let line , charPos = fixLineForIdentifying line p.position.character
700
+
701
+
702
+ let maybeId = QuickParse.GetCompleteIdentifierIsland false line ( charPos)
683
703
match c, maybeId with
684
704
| Error( errors), _ ->
685
705
lgError " Check failed, errors: {errors}" ( errors)
686
706
return None
687
707
| _, None ->
688
- lgInfo3 " No identifier at{file}({line},{char})" file.FullName p.position.line p.position.character
708
+ lgInfo3 " No identifier at{file}({line},{char})" file.FullName p.position.line charPos
689
709
return None
690
710
691
711
| Ok( parseResult, checkResult), Some( id, _, _) ->
692
712
lgInfo " Hover over {id}" id
693
713
let ids = List.ofArray( id.Split( '.' ))
694
- let tips = checkResult.GetToolTip( p.position.line+ 1 , p.position.character + 1 , line, ids, FSharpTokenTag.Identifier)
714
+ let tips = checkResult.GetToolTip( p.position.line+ 1 , charPos + 1 , line, ids, FSharpTokenTag.Identifier)
695
715
lgDebug " Hover tooltipText={text}" tips
696
716
return Some( asHover( tips))
697
717
}
0 commit comments