Skip to content

Commit

Permalink
listen and modify client messages (#7876)
Browse files Browse the repository at this point in the history
  • Loading branch information
StellaHuang95 authored Apr 19, 2024
1 parent 33be9b1 commit 2fa6014
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ internal sealed class PythonLanguageClient : ILanguageClient, ILanguageClientCus
private bool _sentInitialWorkspaceFolders = false;
private FileWatcher.Listener _fileListener;
private static TaskCompletionSource<int> _readyTcs = new System.Threading.Tasks.TaskCompletionSource<int>();
private bool _modifiedInitialize = false;
private bool _loaded = false;
private Timer _deferredSettingsChangedTimer;
private const int _defaultSettingsDelayMS = 2000;
Expand Down Expand Up @@ -561,19 +560,30 @@ private Tuple<StreamData, bool> OnSendToServer(StreamData data) {
messageParams["rootUri"] = "";

// Need to rewrite the message now.
_modifiedInitialize = true;
return Tuple.Create(MessageParser.Serialize(message), false);
return Tuple.Create(MessageParser.Serialize(message), true);
}
}
} else if (message.Value<string>("method") == "textDocument/codeAction") {
if (message.TryGetValue("params", out JToken messageParams)) {
if (messageParams != null && messageParams["range"] != null
&& messageParams["context"] != null
&& messageParams["context"]["_vs_selectionRange"] != null) {
var selectionRange = messageParams["context"]["_vs_selectionRange"];
messageParams["range"]["start"] = selectionRange["start"];
messageParams["range"]["end"] = selectionRange["end"];
return Tuple.Create(MessageParser.Serialize(message), true);
}

}
}
} catch {
// Don't care if this happens. Just skip the message
}
}

// Return the tuple that indicates if we need to keep listening or not
// We need to keep listening if debugging or haven't modified initialize yet
return Tuple.Create(data, !_modifiedInitialize || _isDebugging);
// For now we will keep listening since code action requests can be sent multiple times
return Tuple.Create(data, true);
}

private async Task OnWorkspaceOpening(object sende, EventArgs e) {
Expand Down

0 comments on commit 2fa6014

Please sign in to comment.