Skip to content

Commit

Permalink
Replace this bindings with closures
Browse files Browse the repository at this point in the history
This change is made as per Gabriel's suggestion that the bind semantics
are hairy
(#20 (comment)).
  • Loading branch information
klinvill committed Jan 5, 2024
1 parent 7704a53 commit 4e9697e
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ export class Server {
// method within a closure, or explicitly bind it here. See
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/thiscallbacks
// for the official documentation on this behavior, and
// https://javascript.info/bind for a better explanation.
this.connection.conn.onInitialize(this.onInitialize.bind(this));
this.connection.conn.onInitialized(this.onInitializedHandler.bind(this));
// https://javascript.info/bind for another explanation.
this.connection.conn.onInitialize(params => this.onInitialize(params));
this.connection.conn.onInitialized(() => this.onInitializedHandler());
// We don't do anything special when the configuration changes
this.connection.conn.onDidChangeConfiguration(_change => {
this.updateConfigurationSettings();
Expand All @@ -149,25 +149,25 @@ export class Server {
// Monitored files have change in VSCode
// connection.console.log('We received an file change event');
});
this.connection.conn.onCompletion(this.onCompletion.bind(this));
this.connection.conn.onCompletion(textDocumentPosition => this.onCompletion(textDocumentPosition));
// This handler resolves additional information for the item selected in
// the completion list.
this.connection.conn.onCompletionResolve(
(item: CompletionItem): CompletionItem => {
return item;
}
);
this.connection.conn.onHover(this.onHover.bind(this));
this.connection.conn.onDefinition(this.onDefinition.bind(this));
this.connection.conn.onDocumentRangeFormatting(this.onDocumentRangeFormatting.bind(this));
this.connection.conn.onHover(textDocumentPosition => this.onHover(textDocumentPosition));
this.connection.conn.onDefinition(defParams => this.onDefinition(defParams));
this.connection.conn.onDocumentRangeFormatting(formatParams => this.onDocumentRangeFormatting(formatParams));

// Custom events
this.connection.conn.onRequest("fstar-vscode-assistant/verify-to-position", this.onVerifyToPositionRequest.bind(this));
this.connection.conn.onRequest("fstar-vscode-assistant/lax-to-position", this.onLaxToPositionRequest.bind(this));
this.connection.conn.onRequest("fstar-vscode-assistant/restart", this.onRestartRequest.bind(this));
this.connection.conn.onRequest("fstar-vscode-assistant/text-doc-changed", this.onTextDocChangedRequest.bind(this));
this.connection.conn.onRequest("fstar-vscode-assistant/kill-and-restart-solver", this.onKillAndRestartSolverRequest.bind(this));
this.connection.conn.onRequest("fstar-vscode-assistant/kill-all", this.onKillAllRequest.bind(this));
this.connection.conn.onRequest("fstar-vscode-assistant/verify-to-position", params => this.onVerifyToPositionRequest(params));
this.connection.conn.onRequest("fstar-vscode-assistant/lax-to-position", params => this.onLaxToPositionRequest(params));
this.connection.conn.onRequest("fstar-vscode-assistant/restart", uri => this.onRestartRequest(uri));
this.connection.conn.onRequest("fstar-vscode-assistant/text-doc-changed", params => this.onTextDocChangedRequest(params));
this.connection.conn.onRequest("fstar-vscode-assistant/kill-and-restart-solver", uri => this.onKillAndRestartSolverRequest(uri));
this.connection.conn.onRequest("fstar-vscode-assistant/kill-all", params => this.onKillAllRequest(params));
}

run() {
Expand Down

0 comments on commit 4e9697e

Please sign in to comment.