Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src-node/lsp-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ exports.startServer = async function startServer(params) {
if (code) {
console.error(`[lsp-client][${serverId}] exited code=${code} signal=${signal || 'none'}`);
}
// Fail every in-flight request immediately - the dead process can never answer them, and
// leaving them pending stalls callers until the per-request timeout (2 minutes).
for (const { reject: rejectPending } of serverState.pending.values()) {
rejectPending(new Error(`Server ${serverId} exited with pending request`));
}
serverState.pending.clear();
nodeConnector.triggerPeer('serverExit', { serverId, code, signal, stderr });
if (!hasResolved) {
hasResolved = true;
Expand Down
37 changes: 37 additions & 0 deletions src/extensions/default/TypeScriptSupport/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,43 @@
expect(content("jsconfig.json", { checkJs: true }, false).compilerOptions.checkJs).toBe(false);
});

// LSP quickfixes: diagnostics and fixes are separate channels - after diagnostics land, the
// LintingProvider idle-fetches textDocument/codeAction quickfixes, decorates the cached
// errors, and re-runs inspection so the Fix All button appears. `consol.log(1)` produces
// TS 2552 ("Cannot find name 'consol'") whose quickfix is a single same-file text edit
// ("Change spelling to 'console'") - exactly the admitted shape. Fix application goes
// through Editor.replaceMultipleRanges, so no editor focus is needed (unlike the code-hint
// menu), making this runnable in an unfocused test window.
it("wires LSP quickfixes into the problems panel Fix All workflow", async function () {
const FileSystem = testWindow.brackets.test.FileSystem;
const projectPath = await SpecRunnerUtils.getTempTestDirectory(testRootSpec + "ts");
await jsPromise(SpecRunnerUtils.createTextFile(
path.join(projectPath, "fixable.ts"), "consol.log(1);\n", FileSystem));
await SpecRunnerUtils.loadProjectInTestWindow(projectPath);
await awaitsForDone(SpecRunnerUtils.openProjectFiles(["fixable.ts"]), "open fixable.ts");

await awaitsFor(function () {
return $("#problems-panel").text().indexOf("Cannot find name 'consol'") !== -1;

Check warning on line 348 in src/extensions/default/TypeScriptSupport/unittests.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use `.includes()`, rather than `.indexOf()`, when checking for existence.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6QhU8DAEfseQ4ip-&open=AZ8h6QhU8DAEfseQ4ip-&pullRequest=3005
}, "the spelling diagnostic to appear in the problems panel", 30000);

// The idle codeAction fetch (~800ms after diagnostics settle) attaches the fix and
// nudges a re-run - the Fix All button becoming visible proves the whole chain.
await awaitsFor(function () {
const $btn = $("#problems-panel .problems-fix-all-btn");
return $btn.length && !$btn.hasClass("forced-hidden");
}, "the Fix All button to appear once quickfixes are fetched", 30000);

const editor = EditorManager.getCurrentFullEditor();
$("#problems-panel .problems-fix-all-btn").click();
await awaitsFor(function () {
return editor.document.getText().indexOf("console.log(1);") !== -1;

Check warning on line 361 in src/extensions/default/TypeScriptSupport/unittests.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use `.includes()`, rather than `.indexOf()`, when checking for existence.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6QhU8DAEfseQ4ip_&open=AZ8h6QhU8DAEfseQ4ip_&pullRequest=3005
}, "the quickfix to change consol -> console", 10000);

await awaitsForDone(CommandManager.execute(Commands.FILE_CLOSE, { _forceClose: true }),
"close fixable.ts");
await SpecRunnerUtils.removeTempDirectory();
}, 90000);

// ----- hover quick-actions (Go to Definition / Find Usages) -------------------------------

// Query the hover popover at a position the same way QuickViewManager does internally.
Expand Down
4 changes: 2 additions & 2 deletions src/language/CodeInspection.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ define(function (require, exports, module) {
* htmlMessage:string,
* type:?Type ,
* fix: { // an optional fix, if present will show the fix button
* replace: "text to replace the offset given below",
* replaceText: "text to replace the offset given below",
* rangeOffset: {
* start: number,
* end: number
Expand All @@ -929,7 +929,7 @@ define(function (require, exports, module) {
* @property {string} htmlMessage - The error message to be displayed as HTML.
* @property {?Type} type - The type of the error. Defaults to `Type.WARNING` if unspecified.
* @property {?Object} fix - An optional fix object.
* @property {string} fix.replace - The text to replace the error with.
* @property {string} fix.replaceText - The text to replace the error with.
* @property {Object} fix.rangeOffset - The range within the text to replace.
* @property {number} fix.rangeOffset.start - The start offset of the range.
* @property {number} fix.rangeOffset.end - The end offset of the range.
Expand Down
240 changes: 233 additions & 7 deletions src/languageTools/DefaultProviders.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,11 +814,19 @@
.done(function () {
setJumpPosition(startCurPos);
$deferredHints.resolve();
})
.fail(function () {
$deferredHints.reject();
});
} else { //definition is in current document
setJumpPosition(startCurPos);
$deferredHints.resolve();
}
} else {
// No definition at this position (servers answer null/[] - e.g. tsserver while it
// is still loading the project). MUST settle: an unresolved deferred here leaves
// the NAVIGATE_JUMPTO_DEFINITION command promise pending forever.
$deferredHints.reject();
}
}).fail(function () {
$deferredHints.reject();
Expand All @@ -832,6 +840,19 @@
this._promiseMap = new Map();
this._lastSignature = new Map();
this._validateOnType = false;
// --- quickfix (textDocument/codeAction) state ---
this._quickFixClient = null; // LanguageClient injected by LSPClient._registerProviders
this._rawDiagnostics = new Map(); // filePath -> raw LSP diagnostics (setInspectionResults flattens)
this._quickFixState = new Map(); // filePath -> {timestamp, signature} of the last fetch
this._quickFixTimer = null; // idle-fetch timer (cleared on every newer publish)
// Diagnostics can arrive while their file sits in a background pane (fetches only run for
// the active file) - when such a file becomes active, schedule the fetch it missed.
const self = this;

Check failure on line 850 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not assign `this` to `self`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqA&open=AZ8h6Qmp8DAEfseQ4iqA&pullRequest=3005
EditorManager.on("activeEditorChange", function (evt, current) {
if (current && current.document) {

Check warning on line 852 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqB&open=AZ8h6Qmp8DAEfseQ4iqB&pullRequest=3005
self._scheduleQuickFixFetch(current.document.file._path);
}
});
}

LintingProvider.prototype.setClient = setClient;
Expand All @@ -843,11 +864,19 @@
this._results.delete(filePath);
this._promiseMap.delete(filePath);
this._lastSignature.delete(filePath);
this._rawDiagnostics.delete(filePath);
this._quickFixState.delete(filePath);
} else {
//clear all results
this._results.clear();
this._promiseMap.clear();
this._lastSignature.clear();
this._rawDiagnostics.clear();
this._quickFixState.clear();
}
if (this._quickFixTimer) {
clearTimeout(this._quickFixTimer);
this._quickFixTimer = null;
}
};

Expand All @@ -866,18 +895,15 @@
line: obj.range.start.line,
ch: obj.range.start.character
},
endPos: {
line: obj.range.end.line,
ch: obj.range.end.character
},
message: obj.message,
type: (obj.severity === 1 ? CodeInspection.Type.ERROR : (obj.severity === 2 ? CodeInspection.Type.WARNING : CodeInspection.Type.META))
};
});

this._results.set(filePath, {
errors: errors
});
if(this._promiseMap.get(filePath)) {
this._promiseMap.get(filePath).resolve(this._results.get(filePath));
this._promiseMap.delete(filePath);
}
// Language servers re-publish diagnostics in waves (e.g. syntax then semantic passes) and
// again on every edit - frequently with identical content. Re-running inspection only to
// render the same problems rebuilds the Problems panel for nothing, which both wastes work
Expand All @@ -890,6 +916,19 @@
previous = this._lastSignature.has(filePath) ? this._lastSignature.get(filePath) : "[]",
changed = previous !== signature;
this._lastSignature.set(filePath, signature);

// Keep the EXISTING errors array when content is unchanged: the quickfix layer decorates the
// cached errors with `fix` after an async codeAction fetch, and replacing the array on an
// identical re-publish would silently wipe those fixes without triggering a re-fetch.
if (changed || !this._results.has(filePath)) {
this._results.set(filePath, {
errors: errors
});
}
if(this._promiseMap.get(filePath)) {
this._promiseMap.get(filePath).resolve(this._results.get(filePath));
this._promiseMap.delete(filePath);
}
if (this._validateOnType && changed) {
var editor = EditorManager.getActiveEditor(),
docPath = editor ? editor.document.file._path : "";
Expand All @@ -905,6 +944,193 @@
}
};

// ----- quickfixes (textDocument/codeAction) ------------------------------------------------
// Diagnostics and their fixes are separate LSP channels: fixes must be REQUESTED per range with
// the diagnostics as context. CodeInspection needs fixes ON the errors at scan time, so the flow
// is: retain the raw diagnostics -> idle-fetch code actions (never in the typing hot path) ->
// decorate the cached errors with { replaceText, rangeOffset } -> requestRun() so CodeInspection
// re-pulls and registers them (fix icons + Fix All appear). Server-agnostic: gated purely on the
// server's codeActionProvider capability via LanguageClient.requestCodeActions.

// Fetch this long after diagnostics settle. Typing produces a new publish per change wave, which
// reschedules - so no codeAction traffic while the user is actively typing, and a fetched fix is
// never dead-on-arrival (CodeInspection drops fixes whose document changed anyway).
var QUICKFIX_IDLE_MS = 800;

Check failure on line 958 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqC&open=AZ8h6Qmp8DAEfseQ4iqC&pullRequest=3005
// Per-diagnostic fallback cap, for servers that don't answer a whole-file batched request.
var MAX_QUICKFIX_REQUESTS = 20;

Check failure on line 960 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqD&open=AZ8h6Qmp8DAEfseQ4iqD&pullRequest=3005

/**
* Record the raw diagnostics for a file and schedule an idle quickfix fetch. Called by the
* publishDiagnostics handler right after setInspectionResults.
* @param {string} filePath
* @param {Array<Object>} rawDiagnostics - unflattened LSP diagnostics (range/code/data intact)
*/
LintingProvider.prototype.updateQuickFixes = function (filePath, rawDiagnostics) {
this._rawDiagnostics.set(filePath, rawDiagnostics || []);
this._scheduleQuickFixFetch(filePath);
};

LintingProvider.prototype._scheduleQuickFixFetch = function (filePath) {
var self = this;

Check failure on line 974 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqE&open=AZ8h6Qmp8DAEfseQ4iqE&pullRequest=3005

Check failure on line 974 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not assign `this` to `self`.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqF&open=AZ8h6Qmp8DAEfseQ4iqF&pullRequest=3005
if (!this._quickFixClient || !this._rawDiagnostics.has(filePath)) {
return;
}
var editor = EditorManager.getActiveEditor();

Check failure on line 978 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqG&open=AZ8h6Qmp8DAEfseQ4iqG&pullRequest=3005
if (!editor || editor.document.file._path !== filePath ||
!this._quickFixClient.servesDocument(editor)) {
return; // fixes are only fetched for the active, server-synced document
}
var state = this._quickFixState.get(filePath);
if (state && state.timestamp === editor.document.lastChangeTimestamp &&
state.signature === this._lastSignature.get(filePath)) {
return; // already fetched for this exact document + diagnostics content
}
if (this._quickFixTimer) {
clearTimeout(this._quickFixTimer);
}
this._quickFixTimer = setTimeout(function () {
self._quickFixTimer = null;
self._fetchQuickFixes(filePath);
}, QUICKFIX_IDLE_MS);
};

/**
* @private
* The single admitted fix of a code action, or null. Admitted: a literal quickfix CodeAction,
* not disabled, whose WorkspaceEdit touches EXACTLY this file with EXACTLY one TextEdit (the
* CodeInspection fix contract is one contiguous same-document replace). Legacy bare Commands
* (no edit to apply client-side) are skipped.
* @return {?{replaceText:string, rangeOffset:{start:number, end:number}}}
*/
LintingProvider.prototype._fixFromAction = function (action, editor, filePath) {
if (!action || !action.title || action.disabled) {
return null;
}
if (!action.kind || action.kind.indexOf("quickfix") !== 0) {
return null; // not a quickfix (servers may ignore context.only), or a bare Command
}
var edit = action.edit;

Check failure on line 1012 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqK&open=AZ8h6Qmp8DAEfseQ4iqK&pullRequest=3005
if (!edit) {
return null;
}
var uri = null, edits = null;

Check failure on line 1016 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqL&open=AZ8h6Qmp8DAEfseQ4iqL&pullRequest=3005
if (edit.documentChanges && edit.documentChanges.length === 1 &&

Check warning on line 1017 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqM&open=AZ8h6Qmp8DAEfseQ4iqM&pullRequest=3005
edit.documentChanges[0].textDocument) {
uri = edit.documentChanges[0].textDocument.uri;
edits = edit.documentChanges[0].edits;
} else if (edit.changes) {
var uris = Object.keys(edit.changes);

Check failure on line 1022 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqN&open=AZ8h6Qmp8DAEfseQ4iqN&pullRequest=3005
if (uris.length === 1) {
uri = uris[0];
edits = edit.changes[uri];
}
}
if (!uri || !edits || edits.length !== 1 || typeof edits[0].newText !== "string") {

Check warning on line 1028 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqO&open=AZ8h6Qmp8DAEfseQ4iqO&pullRequest=3005
return null; // multi-file / multi-edit / create-rename ops - beyond the one-replace contract
}
// Compare as decoded platform paths so URI encoding differences can't break the match.
var ownUri = this._quickFixClient.uriForPath(filePath);

Check failure on line 1032 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqP&open=AZ8h6Qmp8DAEfseQ4iqP&pullRequest=3005
if (PathConverters.uriToPath(uri) !== PathConverters.uriToPath(ownUri)) {
return null; // edit lands in a different file
}
var range = edits[0].range;

Check failure on line 1036 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqQ&open=AZ8h6Qmp8DAEfseQ4iqQ&pullRequest=3005
return {
replaceText: edits[0].newText,
rangeOffset: {
start: editor.indexFromPos({ line: range.start.line, ch: range.start.character }),
end: editor.indexFromPos({ line: range.end.line, ch: range.end.character })
}
};
};

// Attach an action's fix to the cached error matching one of the action's diagnostics.
// `forDiagnostic` pins the target in per-diagnostic fallback mode, where the request itself
// identifies the diagnostic even when the server omits action.diagnostics.
LintingProvider.prototype._attachFix = function (errors, action, fix, forDiagnostic) {
var diags = (action.diagnostics && action.diagnostics.length) ? action.diagnostics

Check warning on line 1050 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqS&open=AZ8h6Qmp8DAEfseQ4iqS&pullRequest=3005

Check failure on line 1050 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqR&open=AZ8h6Qmp8DAEfseQ4iqR&pullRequest=3005
: (forDiagnostic ? [forDiagnostic] : []);

Check warning on line 1051 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested ternary operation into an independent statement.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqT&open=AZ8h6Qmp8DAEfseQ4iqT&pullRequest=3005
for (var d = 0; d < diags.length; d++) {

Check failure on line 1052 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqV&open=AZ8h6Qmp8DAEfseQ4iqV&pullRequest=3005
var diag = diags[d];

Check failure on line 1053 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqW&open=AZ8h6Qmp8DAEfseQ4iqW&pullRequest=3005
for (var i = 0; i < errors.length; i++) {

Check failure on line 1054 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqY&open=AZ8h6Qmp8DAEfseQ4iqY&pullRequest=3005
var err = errors[i];

Check failure on line 1055 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqZ&open=AZ8h6Qmp8DAEfseQ4iqZ&pullRequest=3005
if (err.pos.line === diag.range.start.line && err.pos.ch === diag.range.start.character &&
err.message === diag.message && (!err.fix || action.isPreferred)) {
err.fix = fix;
return true;
}
}

Check warning on line 1061 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expected a `for-of` loop instead of a `for` loop with this simple iteration.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqX&open=AZ8h6Qmp8DAEfseQ4iqX&pullRequest=3005
}
return false;
};

LintingProvider.prototype._fetchQuickFixes = async function (filePath) {

Check failure on line 1066 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 25 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqa&open=AZ8h6Qmp8DAEfseQ4iqa&pullRequest=3005
var self = this;

Check failure on line 1067 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqb&open=AZ8h6Qmp8DAEfseQ4iqb&pullRequest=3005
var client = this._quickFixClient;

Check failure on line 1068 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqd&open=AZ8h6Qmp8DAEfseQ4iqd&pullRequest=3005
var editor = EditorManager.getActiveEditor();

Check failure on line 1069 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqe&open=AZ8h6Qmp8DAEfseQ4iqe&pullRequest=3005
var diagnostics = this._rawDiagnostics.get(filePath) || [];
var cached = this._results.get(filePath);

Check failure on line 1071 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqg&open=AZ8h6Qmp8DAEfseQ4iqg&pullRequest=3005
if (!client || !editor || editor.document.file._path !== filePath ||
!client.servesDocument(editor) || !diagnostics.length || !cached) {
return;
}
var fetchedAt = editor.document.lastChangeTimestamp;

Check failure on line 1076 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqh&open=AZ8h6Qmp8DAEfseQ4iqh&pullRequest=3005
// Record the fetch attempt up front so identical re-publishes don't re-fetch, even when the
// server turns out to have no fixes for these diagnostics.
this._quickFixState.set(filePath, {
timestamp: fetchedAt,
signature: this._lastSignature.get(filePath)
});

try {
// One batched whole-file request first (spec-legal, one round trip for every fix)...
var lastLine = editor.lineCount() - 1;

Check failure on line 1086 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqi&open=AZ8h6Qmp8DAEfseQ4iqi&pullRequest=3005
var wholeFile = {

Check failure on line 1087 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqj&open=AZ8h6Qmp8DAEfseQ4iqj&pullRequest=3005
start: { line: 0, character: 0 },
end: { line: lastLine, character: editor.document.getLine(lastLine).length }
};
var actions = await client.requestCodeActions({

Check failure on line 1091 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqk&open=AZ8h6Qmp8DAEfseQ4iqk&pullRequest=3005
filePath: filePath, range: wholeFile, diagnostics: diagnostics
});
var attached = 0;

Check failure on line 1094 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iql&open=AZ8h6Qmp8DAEfseQ4iql&pullRequest=3005
if (actions && actions.length) {

Check warning on line 1095 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqm&open=AZ8h6Qmp8DAEfseQ4iqm&pullRequest=3005
for (var i = 0; i < actions.length; i++) {

Check failure on line 1096 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqo&open=AZ8h6Qmp8DAEfseQ4iqo&pullRequest=3005
var resolved = await client.resolveCodeAction(actions[i]); // no-op unless deferred

Check failure on line 1097 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqp&open=AZ8h6Qmp8DAEfseQ4iqp&pullRequest=3005
var fix = this._fixFromAction(resolved, editor, filePath);

Check failure on line 1098 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqq&open=AZ8h6Qmp8DAEfseQ4iqq&pullRequest=3005
if (fix && this._attachFix(cached.errors, resolved, fix, null)) {
attached++;
}
}

Check warning on line 1102 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expected a `for-of` loop instead of a `for` loop with this simple iteration.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqn&open=AZ8h6Qmp8DAEfseQ4iqn&pullRequest=3005
} else {
// ...falling back to capped per-diagnostic requests for servers that don't answer
// the batched form.
var capped = diagnostics.slice(0, MAX_QUICKFIX_REQUESTS);

Check failure on line 1106 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqr&open=AZ8h6Qmp8DAEfseQ4iqr&pullRequest=3005
for (var d = 0; d < capped.length; d++) {

Check failure on line 1107 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqt&open=AZ8h6Qmp8DAEfseQ4iqt&pullRequest=3005
var acts = await client.requestCodeActions({

Check failure on line 1108 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqu&open=AZ8h6Qmp8DAEfseQ4iqu&pullRequest=3005
filePath: filePath, range: capped[d].range, diagnostics: [capped[d]]
});
for (var a = 0; acts && a < acts.length; a++) {

Check failure on line 1111 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqv&open=AZ8h6Qmp8DAEfseQ4iqv&pullRequest=3005
var res = await client.resolveCodeAction(acts[a]);

Check failure on line 1112 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqw&open=AZ8h6Qmp8DAEfseQ4iqw&pullRequest=3005
var f = this._fixFromAction(res, editor, filePath);

Check failure on line 1113 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqx&open=AZ8h6Qmp8DAEfseQ4iqx&pullRequest=3005
if (f && this._attachFix(cached.errors, res, f, capped[d])) {
attached++;
break; // one fix per diagnostic
}
}
}

Check warning on line 1119 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Expected a `for-of` loop instead of a `for` loop with this simple iteration.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqs&open=AZ8h6Qmp8DAEfseQ4iqs&pullRequest=3005
}
// Re-render only when something changed AND the document didn't move under us (a moved
// document gets fresh diagnostics -> a fresh fetch; its fixes would be dropped anyway).
var activeEditor = EditorManager.getActiveEditor();

Check failure on line 1123 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected var, use let or const instead.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AZ8h6Qmp8DAEfseQ4iqy&open=AZ8h6Qmp8DAEfseQ4iqy&pullRequest=3005
if (attached && activeEditor && activeEditor.document.file._path === filePath &&
activeEditor.document.lastChangeTimestamp === fetchedAt &&
self._isRegisteredInspector(filePath)) {
CodeInspection.requestRun();
}
} catch (err) {
console.warn("[LSP] quickfix fetch failed:", err && (err.message || err));
}
};

/**
* @private
* @param {string} filePath - active document path
Expand Down
Loading
Loading