Skip to content

Commit

Permalink
Fix code actions construction for "replace" tasks
Browse files Browse the repository at this point in the history
Also add missing information in the action.
  • Loading branch information
elsassph committed May 21, 2021
1 parent 4a0f857 commit c97153f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/CodeActionUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,26 @@ export class CodeActionUtil {
TextEdit.insert(change.position, change.newText)
);
} else if (change.type === 'replace') {
TextEdit.replace(change.range, change.newText);
edit.changes[uri].push(
TextEdit.replace(change.range, change.newText)
);
}
}
return CodeAction.create(obj.title, edit);
const action = CodeAction.create(obj.title, edit, obj.kind);
action.isPreferred = obj.isPreferred;
action.diagnostics = this.serializableDiagnostics(obj.diagnostics);
return action;
}

public serializableDiagnostics(diagnostics: Diagnostic[]) {
return diagnostics?.map(({ range, severity, code, source, message, relatedInformation }) => ({
range: range,
severity: severity,
source: source,
code: code,
message: message,
relatedInformation: relatedInformation
}));
}
}

Expand Down

0 comments on commit c97153f

Please sign in to comment.