fix(server): reject invalid params consistently across handlers
Document symbols, code lens, and code action swallowed a params parse failure and answered success with an empty result, while formatting, completion, and hover returned INVALID_PARAMS for the same failure. All six now return the error, which is what JSON-RPC prescribes and makes a client bug visible instead of looking like an empty document.
This commit is contained in:
+25
-13
@@ -544,18 +544,26 @@ impl Server {
|
||||
id: Value,
|
||||
params: Option<Value>,
|
||||
) -> Vec<Outgoing> {
|
||||
let items = parse_params::<DocumentSymbolParams>(params)
|
||||
.ok()
|
||||
.and_then(|p| self.documents.get(&p.text_document.uri))
|
||||
let params: DocumentSymbolParams = match require_params(&id, params) {
|
||||
Ok(params) => params,
|
||||
Err(out) => return out,
|
||||
};
|
||||
let items = self
|
||||
.documents
|
||||
.get(¶ms.text_document.uri)
|
||||
.map(|doc| symbols::document_symbols(doc, self.encoding))
|
||||
.unwrap_or_default();
|
||||
ok(id, items)
|
||||
}
|
||||
|
||||
fn on_code_lens(&self, id: Value, params: Option<Value>) -> Vec<Outgoing> {
|
||||
let lenses = parse_params::<CodeLensParams>(params)
|
||||
.ok()
|
||||
.and_then(|p| self.documents.get(&p.text_document.uri))
|
||||
let params: CodeLensParams = match require_params(&id, params) {
|
||||
Ok(params) => params,
|
||||
Err(out) => return out,
|
||||
};
|
||||
let lenses = self
|
||||
.documents
|
||||
.get(¶ms.text_document.uri)
|
||||
.map(|doc| {
|
||||
schema_action::code_lenses(
|
||||
doc,
|
||||
@@ -572,16 +580,20 @@ impl Server {
|
||||
id: Value,
|
||||
params: Option<Value>,
|
||||
) -> Vec<Outgoing> {
|
||||
let actions = parse_params::<CodeActionParams>(params)
|
||||
.ok()
|
||||
.and_then(|p| {
|
||||
let doc = self.documents.get(&p.text_document.uri)?;
|
||||
Some(schema_action::code_actions(
|
||||
let params: CodeActionParams = match require_params(&id, params) {
|
||||
Ok(params) => params,
|
||||
Err(out) => return out,
|
||||
};
|
||||
let actions = self
|
||||
.documents
|
||||
.get(¶ms.text_document.uri)
|
||||
.map(|doc| {
|
||||
schema_action::code_actions(
|
||||
doc,
|
||||
&self.schema_store,
|
||||
self.encoding,
|
||||
p.range,
|
||||
))
|
||||
params.range,
|
||||
)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
ok(id, actions)
|
||||
|
||||
Reference in New Issue
Block a user