Skip to content

Commit

Permalink
fix textDocument/documentSymbol
Browse files Browse the repository at this point in the history
  • Loading branch information
JJPro committed Apr 10, 2020
1 parent b283c2b commit 4d5d822
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions text-document.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)]
[_
Expand All @@ -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)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down

0 comments on commit 4d5d822

Please sign in to comment.