From 4d5d822edd36e97aa4dcb7cebfaf65318979d4b9 Mon Sep 17 00:00:00 2001 From: Jason Ji Date: Thu, 9 Apr 2020 21:13:24 -0400 Subject: [PATCH] fix textDocument/documentSymbol --- text-document.rkt | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/text-document.rkt b/text-document.rkt index 6a026d0..b33cdb9 100644 --- a/text-document.rkt +++ b/text-document.rkt @@ -129,7 +129,7 @@ ;; Hover request ;; Returns an object conforming to the Hover interface, to -;; be used as the result of the response message. +;; be used as the result of the response message. (define (hover id params) (match params [(hash-table ['textDocument (DocIdentifier #:uri uri)] @@ -239,25 +239,28 @@ (hash-ref open-docs (string->symbol uri))) (define in (open-input-string (send doc-text get-text))) (port-count-lines! in) - (define lexer (get-lexer in)) + (define lexer (get-lexer in)) ;; lexer: token producer + (define after-define? (box #f)) (define results (for/fold ([out empty]) ([lst (in-port (lexer-wrap lexer) in)]) (match-define (list text type paren? start end) lst) - (cond [(set-member? '(constant string symbol) type) - (define kind (match type - ['constant SymbolKind-Constant] - ['string SymbolKind-String] - ['symbol SymbolKind-Variable])) - (define range - (Range #:start (abs-pos->Pos doc-text start) - #:end (abs-pos->Pos doc-text end))) - (define sym-info - (SymbolInfo #:name text - #:kind kind - #:location (Location #:uri uri - #:range range))) - (cons sym-info out)] + (cond [(eq? 'symbol type) + (cond [(set-member? '("define" "define-type") text) + (set-box! after-define? #t) + out] + [(unbox after-define?) + (set-box! after-define? #f) + (define range + (Range #:start (abs-pos->Pos doc-text start) + #:end (abs-pos->Pos doc-text end))) + (define sym-info + (SymbolInfo #:name text + #:kind SymbolKind-Function + #:location (Location #:uri uri + #:range range))) + (cons sym-info out)] + [else out])] [else out]))) (success-response id results)] [_ @@ -277,9 +280,15 @@ (match-define-values (_ _ _ _ _ _ lexer) (module-lexer in 0 #f)) - (if (procedure? lexer) ;; TODO: Is this an issue with module-lexer docs? - lexer - (error 'get-lexer "~v" lexer))) + #| + lexer is one of: + - 'before-lang-line + - lexer, the procedure + loop until it is a procedure + |# + (if (procedure? lexer) + lexer + (get-lexer in))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;