Skip to content

Conversation

@dannypsnl
Copy link
Collaborator

@dannypsnl dannypsnl commented Jan 28, 2026

Extract server concept from current complicated msg-io interaction, so we don't need to use message flushing in testing.

  1. Introduce a layer server% with an async channel ch
    • output will be sent to ch
    • server request also sent to ch
    • tests/client.rkt will not create subprocess but interact with server via async channel now (no need msg-io)
  2. Modify main.rkt to work with server abstraction (now main loop is the only place flush message)
  3. Update related tests

resolve #157

@dannypsnl

This comment was marked as resolved.

@6cdh
Copy link
Collaborator

6cdh commented Jan 28, 2026

The two hash tables are literally same.

It seems chk library issues. We can replace it with rackunit, use rackunit-lib in info.rkt.

@dannypsnl
Copy link
Collaborator Author

Now only leave hover.rkt has bug, I will check how to fix it tomorrow

@dannypsnl
Copy link
Collaborator Author

The two hash tables are literally same.

It seems chk library issues. We can replace it with rackunit, use rackunit-lib in info.rkt.

Yes, I think we should remove chk library in the future, just make a note here first.

@dannypsnl
Copy link
Collaborator Author

ok, hover is not always failed, because the refactoring we make test be fast enough, doc analyze might not complete in this case……

@dannypsnl
Copy link
Collaborator Author

success case:

raco test: (submod (file "tests/textDocument/hover.rkt") test)
'#hasheq((jsonrpc . "2.0") (method . "textDocument/publishDiagnostics") (params . #hasheq((diagnostics . ()) (uri . "file:///test.rkt"))))
'#hasheq((id . 2) (jsonrpc . "2.0") (result . #hasheq((contents . "imported from racket/base - [online docs](https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28quote._%7E23%7E25kernel%29._list%29%29)\n\n---\n```\n(list v ...) -> list?\n  v : any/c\n```\n---\nReturns a newly allocated list containing the *v*s as its elements.\n\nExamples:\n\n```\n> (list 1 2 3 4)\n'(1 2 3 4)\n> (list (list 1 2) (list 3 4))\n'((1 2) (3 4))\n```\n\n") (range . #hasheq((end . #hasheq((character . 5) (line . 2))) (start . #hasheq((character . 1) (line . 2))))))))

failed case:

raco test: (submod (file "tests/textDocument/hover.rkt") test)
'#hasheq((jsonrpc . "2.0") (method . "textDocument/publishDiagnostics") (params . #hasheq((diagnostics . ()) (uri . "file:///test.rkt"))))
'#hasheq((id . 2) (jsonrpc . "2.0") (result . #hasheq((contents . ""))))
FAILURE
kind      : "predicate"
predicate : #<procedure:identity>
actual    : #f
            from
            <pkgs>/racket-langserver/tests/textDocument/hover.rkt:35:13: (not (string=? "" (jsexpr-ref resp '(result contents))))
value     : #f
predicate : "not false"

FAILURE
kind      : "predicate"
predicate : #<procedure:identity>
actual    : #f
            from
            <pkgs>/racket-langserver/tests/textDocument/hover.rkt:37:13: (jsexpr-has-key? resp '(result range start line))
value     : #f
predicate : "not false"

FAILURE
kind      : "predicate"
predicate : #<procedure:identity>
actual    : #f
            from
            <pkgs>/racket-langserver/tests/textDocument/hover.rkt:38:13: (jsexpr-has-key? resp '(result range start character))
value     : #f
predicate : "not false"

FAILURE
kind      : "predicate"
predicate : #<procedure:identity>
actual    : #f
            from
            <pkgs>/racket-langserver/tests/textDocument/hover.rkt:39:13: (jsexpr-has-key? resp '(result range end line))
value     : #f
predicate : "not false"

FAILURE
kind      : "predicate"
predicate : #<procedure:identity>
actual    : #f
            from
            <pkgs>/racket-langserver/tests/textDocument/hover.rkt:40:13: (jsexpr-has-key? resp '(result range end character))
value     : #f
predicate : "not false"

--------------------
ERROR
name:       check-equal?
location:   tests/textDocument/hover.rkt:41:8

hash-ref: no value found for key
  key: 'range
--------------------
--------------------
ERROR
name:       check-equal?
location:   tests/textDocument/hover.rkt:42:8

hash-ref: no value found for key
  key: 'range
--------------------
--------------------
ERROR
name:       check-equal?
location:   tests/textDocument/hover.rkt:43:8

hash-ref: no value found for key
  key: 'range
--------------------
--------------------
ERROR
name:       check-equal?
location:   tests/textDocument/hover.rkt:44:8

hash-ref: no value found for key
  key: 'range
--------------------

@dannypsnl dannypsnl requested a review from 6cdh January 28, 2026 16:19
@dannypsnl dannypsnl marked this pull request as ready for review January 28, 2026 16:19
@dannypsnl
Copy link
Collaborator Author

I don't see reasonable fix for hover.rkt, the rest functionality seems work exact as desired. If no other solutions, we can disable hover.rkt for now.

The test client still not prefect, in the future we should gradually change it (e.g. client-wait-response should take an argument id to skip responses with unexpected id)

@dannypsnl dannypsnl changed the title Extract server concept from current complicated msg-io interaction Extract server concept from current complicated msg-io interaction Jan 28, 2026
Comment on lines +5 to +7
(define current-server #f)
(define (set-current-server! s)
(set! current-server s))
Copy link
Collaborator Author

@dannypsnl dannypsnl Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the best way, but parameterize cannot make check-syntax.rkt use this.

Maybe the complete refactoring should put every methods into server%?

1. include server request we use async-channel
2. main loop will take message from async-channel and flush it via stdio
3. fix tests
introduce notification-channel for this case

misc:
- use rackunit in hover.rkt
- use rackunit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactoring to extract JSON-RPC server and client

2 participants