Skip to content

Commit

Permalink
Fixes tooltips on tokens that had a trailing left paren
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Oct 10, 2022
1 parent fc1af1f commit 2213385
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/FsAutoComplete.Core/Lexer.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace FsAutoComplete

open FSharp.Compiler.Tokenization

open FsAutoComplete.Logging
open FsAutoComplete.Logging.Types
type SymbolKind =
| Ident
| Operator
Expand Down Expand Up @@ -37,6 +38,7 @@ type private DraftToken =
RightColumn = token.LeftColumn + token.FullMatchedLength - 1 }

module Lexer =
let logger = LogProvider.getLoggerByName "Lexer"
/// Return all tokens of current line
let tokenizeLine (args: string[]) lineStr =
let defines =
Expand Down Expand Up @@ -81,7 +83,7 @@ module Lexer =
else
Other
elif token.Tag = FSharpTokenTag.LPAREN then
if token.FullMatchedLength = 1 && lineStr.[token.LeftColumn + 1] = '|' then
if token.FullMatchedLength = 1 && lineStr.Length > token.LeftColumn + 1 && lineStr.[token.LeftColumn + 1] = '|' then
ActivePattern
else
Other
Expand Down Expand Up @@ -264,7 +266,16 @@ module Lexer =

try
getSymbolFromTokens tokens line col lineStr lookupKind
with _ ->
with e ->
logger.error(
Log.setMessage "getSymbol failed: {line} {col} {lineStr} {lookupKind} {args}"
>> Log.addContextDestructured "line" line
>> Log.addContextDestructured "col" col
>> Log.addContextDestructured "lineStr" lineStr
>> Log.addContextDestructured "lookupKind" lookupKind
>> Log.addContextDestructured "args" args
>> Log.addExn e
)
//LoggingService.LogInfo (sprintf "Getting lex symbols failed with %O" e)
None

Expand Down
14 changes: 13 additions & 1 deletion test/FsAutoComplete.Tests.Lsp/CoreTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,19 @@ let tooltipTests state =
""
"* `'a` is `int`"
"* `'b` is `int`"
"* `'c` is `int`" ] ] ]
"* `'c` is `int`" ]
verifySignature
48
28
(concatLines
[
"static member Start:"
" body : (MailboxProcessor<string> -> Async<unit>) *"
" cancellationToken: option<System.Threading.CancellationToken>"
" -> MailboxProcessor<string>"
]
)
] ]

let closeTests state =
// Note: clear diagnostics also implies clear caches (-> remove file & project options from State).
Expand Down
5 changes: 5 additions & 0 deletions test/FsAutoComplete.Tests.Lsp/TestCases/Tooltips/Script.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ let (^) x y = x + y
let inline add x y = x + y

let result = add 5 5

let mailbox =
MailboxProcessor<string>.Start(
fun _ -> async.Return()
)

0 comments on commit 2213385

Please sign in to comment.