-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from georgestagg/null-lsp
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { createUri, LanguageServerClient } from "./client"; | ||
import { LSPClient } from "./lsp-client"; | ||
import { | ||
AbstractMessageReader, | ||
AbstractMessageWriter, | ||
createMessageConnection, | ||
} from "vscode-jsonrpc"; | ||
|
||
let nullClient: NullClient | null = null; | ||
|
||
/** | ||
* This returns a NullClient object. If this is called multiple times, it | ||
* will return the same object each time. | ||
*/ | ||
export function ensureNullClient(): NullClient { | ||
if (!nullClient) { | ||
nullClient = new NullClient(); | ||
} | ||
return nullClient; | ||
} | ||
|
||
export class NullMessageReader extends AbstractMessageReader { | ||
public listen() { | ||
return { dispose: () => {} }; | ||
} | ||
} | ||
|
||
export class NullMessageWriter extends AbstractMessageWriter { | ||
public async write() {} | ||
public end(): void {} | ||
} | ||
|
||
/** | ||
* A "null" LSP client that listens for messages but does nothing. | ||
*/ | ||
export class NullClient extends LSPClient { | ||
constructor() { | ||
const conn = createMessageConnection( | ||
new NullMessageReader(), | ||
new NullMessageWriter() | ||
); | ||
conn.listen(); | ||
const client = new LanguageServerClient(conn, "en", createUri("")); | ||
super(client); | ||
} | ||
} |