diff --git a/src/extensions/default/HTMLCodeHints/html-lint.js b/src/extensions/default/HTMLCodeHints/html-lint.js
index aa10ec1d80..f858fe57f6 100644
--- a/src/extensions/default/HTMLCodeHints/html-lint.js
+++ b/src/extensions/default/HTMLCodeHints/html-lint.js
@@ -92,17 +92,24 @@ define(function (require, exports, module) {
configID,
config: projectSpecificOptions
}).then(lintResult =>{
- const editor = EditorManager.getCurrentFullEditor();
+ let editor = EditorManager.getCurrentFullEditor();
if(!editor || editor.document.file.fullPath !== fullPath) {
- reject(new Error("Lint failed as "+ ProjectManager.getProjectRelativeOrDisplayPath(fullPath)
- + " is not active."));
- return;
+ // this is not the active editor the lint is about. so the html validate api sends the startPos of
+ // the error, but doesn't send the end pos, instead it sends the end offset. We need end line:ch pos
+ //to highlight error properly, and computing that needs an editor(or we need to impl that logic)
+ // so for now, we use the active editor if there is one to properly underline errors, and if we
+ // cant find the active editor, we will do an approximation on the current line
+ editor = null;
}
if (lintResult && lintResult.length) {
lintResult = lintResult.map(function (lintError) {
return {
- pos: editor.posFromIndex(lintError.start),
- endPos: editor.posFromIndex(lintError.end),
+ pos: editor ? editor.posFromIndex(lintError.start) : lintError.startPos,
+ endPos: editor ? editor.posFromIndex(lintError.end): {
+ line: lintError.startPos.line,
+ // highlightOffset can span multiple lines, so this is at best an approximation
+ ch: lintError.startPos.ch + lintError.highlightOffset
+ },
message: `${lintError.message} (${lintError.ruleId})`,
type: getTypeFromSeverity(lintError.severity),
moreInfoURL: lintError.ruleUrl
diff --git a/src/extensions/default/HTMLCodeHints/worker/html-worker.js b/src/extensions/default/HTMLCodeHints/worker/html-worker.js
index 9a6a275698..371d753bd7 100644
--- a/src/extensions/default/HTMLCodeHints/worker/html-worker.js
+++ b/src/extensions/default/HTMLCodeHints/worker/html-worker.js
@@ -68,6 +68,11 @@
if(result.messages && result.messages.length) {
for(let message of result.messages){
errors.push({
+ // The starting position of the error (0-based line and column index)
+ startPos: {line: (message.line || 1) - 1, ch: (message.column || 1) - 1},
+ // The length (in characters) of the error from the starting position. this is an offset
+ // than can span multiple lines.
+ highlightOffset: (message.size || 1),
start: message.offset,
end: message.offset + (message.size || 1) - 1,
severity: message.severity,
diff --git a/test/spec/Extn-HTMLCodeHints-Lint-integ-test.js b/test/spec/Extn-HTMLCodeHints-Lint-integ-test.js
index 96d10710c5..c09f9ddea0 100644
--- a/test/spec/Extn-HTMLCodeHints-Lint-integ-test.js
+++ b/test/spec/Extn-HTMLCodeHints-Lint-integ-test.js
@@ -195,5 +195,14 @@ define(function (require, exports, module) {
await SpecRunnerUtils.deletePathAsync(testProjectsFolder + testFile, true, FileSystem);
}, 5000);
}
+
+ it(`should lint non active html files`, async function () {
+ const htmlPath = path.join(testProjectsFolder, "simple1.html");
+ const codeInspectionResults = await jsPromise(
+ CodeInspection.inspectFile(FileSystem.getFileForPath(htmlPath)));
+ expect(codeInspectionResults[0].result.errors.length).toBe(1);
+ expect(codeInspectionResults[0].result.errors[0].pos).toEql({line: 1, ch: 1});
+ expect(codeInspectionResults[0].result.errors[0].endPos).toEql({line: 1, ch: 5});
+ }, 5000);
});
});