@@ -353,12 +353,28 @@ type Server(client: ILanguageClient,useCache:bool) =
353353 /// Request that ` uri ` be checked when the user stops doing things for 1 second
354354 let backgroundCheck = DebounceCheck( doCheck, 1000 )
355355 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+
356369 /// Find the symbol at a position
357370 let symbolAt ( textDocument : TextDocumentIdentifier , position : Position ): Async < FSharpSymbolUse option > =
358371 async {
359372 let file = normedFileInfo( textDocument.uri.LocalPath)
360373 let! c = checkOpenFile( file, true , false )
361374 let line = lineContent( file, position.line)
375+
376+ let line , charPos = fixLineForIdentifying line position.character
377+
362378 let maybeId = QuickParse.GetCompleteIdentifierIsland false line ( position.character)
363379 match c, maybeId with
364380 | Error( errors), _ ->
@@ -679,19 +695,23 @@ type Server(client: ILanguageClient,useCache:bool) =
679695 let file = normedFileInfo( p.textDocument.uri.LocalPath)
680696 let! c = checkOpenFile( file, true , false )
681697 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)
683703 match c, maybeId with
684704 | Error( errors), _ ->
685705 lgError " Check failed, errors: {errors}" ( errors)
686706 return None
687707 | _, 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
689709 return None
690710
691711 | Ok( parseResult, checkResult), Some( id, _, _) ->
692712 lgInfo " Hover over {id}" id
693713 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)
695715 lgDebug " Hover tooltipText={text}" tips
696716 return Some( asHover( tips))
697717 }
0 commit comments