@marko/language-server 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +112 -19
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +112 -19
- package/dist/index.mjs.map +2 -2
- package/package.json +12 -12
package/dist/index.mjs
CHANGED
|
@@ -754,32 +754,114 @@ var doComplete = async (doc, params) => {
|
|
|
754
754
|
import path4 from "path";
|
|
755
755
|
import { Project as Project2 } from "@marko/language-tools";
|
|
756
756
|
import { DiagnosticSeverity } from "vscode-languageserver";
|
|
757
|
+
import { DiagnosticType } from "@marko/babel-utils";
|
|
757
758
|
var markoErrorRegExp = /^(.+?)\.marko(?:\((\d+)(?:\s*,\s*(\d+))?\))?: (.*)$/gm;
|
|
758
759
|
var doValidate = (doc) => {
|
|
759
760
|
const filename = getFSPath(doc);
|
|
760
761
|
const diagnostics = [];
|
|
761
762
|
try {
|
|
762
|
-
Project2.getCompiler(
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
763
|
+
const { meta } = Project2.getCompiler(
|
|
764
|
+
filename && path4.dirname(filename)
|
|
765
|
+
).compileSync(doc.getText(), filename || "untitled.marko", {
|
|
766
|
+
code: false,
|
|
767
|
+
output: "migrate",
|
|
768
|
+
sourceMaps: false,
|
|
769
|
+
errorRecovery: true,
|
|
770
|
+
babelConfig: {
|
|
771
|
+
caller: {
|
|
772
|
+
name: "@marko/language-server",
|
|
773
|
+
supportsStaticESM: true,
|
|
774
|
+
supportsDynamicImport: true,
|
|
775
|
+
supportsTopLevelAwait: true,
|
|
776
|
+
supportsExportNamespaceFrom: true
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
if (meta.diagnostics) {
|
|
781
|
+
for (const diag of meta.diagnostics) {
|
|
782
|
+
const range = diag.loc ? {
|
|
783
|
+
start: {
|
|
784
|
+
line: diag.loc.start.line - 1,
|
|
785
|
+
character: diag.loc.start.column
|
|
786
|
+
},
|
|
787
|
+
end: {
|
|
788
|
+
line: diag.loc.end.line - 1,
|
|
789
|
+
character: diag.loc.end.column
|
|
776
790
|
}
|
|
791
|
+
} : {
|
|
792
|
+
start: { line: 0, character: 0 },
|
|
793
|
+
end: { line: 0, character: 0 }
|
|
794
|
+
};
|
|
795
|
+
let severity;
|
|
796
|
+
switch (diag.type) {
|
|
797
|
+
case DiagnosticType.Warning:
|
|
798
|
+
case DiagnosticType.Deprecation:
|
|
799
|
+
severity = DiagnosticSeverity.Warning;
|
|
800
|
+
break;
|
|
801
|
+
case DiagnosticType.Suggestion:
|
|
802
|
+
severity = DiagnosticSeverity.Hint;
|
|
803
|
+
break;
|
|
804
|
+
default:
|
|
805
|
+
severity = DiagnosticSeverity.Error;
|
|
806
|
+
break;
|
|
777
807
|
}
|
|
808
|
+
diagnostics.push({
|
|
809
|
+
range,
|
|
810
|
+
source: "marko",
|
|
811
|
+
code: void 0,
|
|
812
|
+
tags: void 0,
|
|
813
|
+
severity,
|
|
814
|
+
message: diag.label
|
|
815
|
+
});
|
|
778
816
|
}
|
|
779
|
-
|
|
780
|
-
} catch (
|
|
817
|
+
}
|
|
818
|
+
} catch (err) {
|
|
819
|
+
addDiagnosticsForError(err, diagnostics);
|
|
820
|
+
}
|
|
821
|
+
return diagnostics;
|
|
822
|
+
};
|
|
823
|
+
function addDiagnosticsForError(err, diagnostics) {
|
|
824
|
+
if (!isError(err)) {
|
|
825
|
+
diagnostics.push({
|
|
826
|
+
range: {
|
|
827
|
+
start: { line: 0, character: 0 },
|
|
828
|
+
end: { line: 0, character: 0 }
|
|
829
|
+
},
|
|
830
|
+
source: "marko",
|
|
831
|
+
code: void 0,
|
|
832
|
+
tags: void 0,
|
|
833
|
+
severity: DiagnosticSeverity.Error,
|
|
834
|
+
message: String(err)
|
|
835
|
+
});
|
|
836
|
+
} else if (isAggregateError(err)) {
|
|
837
|
+
for (const nestedError of err.errors) {
|
|
838
|
+
addDiagnosticsForError(nestedError, diagnostics);
|
|
839
|
+
}
|
|
840
|
+
} else if (isErrorWithLoc(err)) {
|
|
841
|
+
const message = err.label || err.message || err.stack;
|
|
842
|
+
if (!message)
|
|
843
|
+
return;
|
|
844
|
+
const { loc } = err;
|
|
845
|
+
diagnostics.push({
|
|
846
|
+
range: {
|
|
847
|
+
start: {
|
|
848
|
+
line: loc.start.line - 1,
|
|
849
|
+
character: loc.start.column
|
|
850
|
+
},
|
|
851
|
+
end: {
|
|
852
|
+
line: loc.end.line - 1,
|
|
853
|
+
character: loc.end.column
|
|
854
|
+
}
|
|
855
|
+
},
|
|
856
|
+
source: "marko",
|
|
857
|
+
code: void 0,
|
|
858
|
+
tags: void 0,
|
|
859
|
+
severity: DiagnosticSeverity.Error,
|
|
860
|
+
message
|
|
861
|
+
});
|
|
862
|
+
} else {
|
|
781
863
|
let match;
|
|
782
|
-
while (match = markoErrorRegExp.exec(
|
|
864
|
+
while (match = markoErrorRegExp.exec(err.message)) {
|
|
783
865
|
const [, , rawLine, rawCol, message] = match;
|
|
784
866
|
const pos = {
|
|
785
867
|
line: (parseInt(rawLine, 10) || 1) - 1,
|
|
@@ -795,8 +877,19 @@ var doValidate = (doc) => {
|
|
|
795
877
|
});
|
|
796
878
|
}
|
|
797
879
|
}
|
|
798
|
-
|
|
799
|
-
|
|
880
|
+
}
|
|
881
|
+
function isError(err) {
|
|
882
|
+
return err != null && typeof err === "object" && typeof err.message === "string";
|
|
883
|
+
}
|
|
884
|
+
function isAggregateError(err) {
|
|
885
|
+
return Array.isArray(err == null ? void 0 : err.errors);
|
|
886
|
+
}
|
|
887
|
+
function isErrorWithLoc(err) {
|
|
888
|
+
const loc = err == null ? void 0 : err.loc;
|
|
889
|
+
if (typeof loc !== "object")
|
|
890
|
+
return false;
|
|
891
|
+
return loc !== null && typeof loc === "object" && typeof loc.start === "object" && typeof loc.end === "object" && typeof loc.start.line === "number" && typeof loc.start.column === "number" && typeof loc.end.line === "number" && typeof loc.end.column === "number";
|
|
892
|
+
}
|
|
800
893
|
|
|
801
894
|
// src/service/marko/hover/index.ts
|
|
802
895
|
import { NodeType as NodeType4 } from "@marko/language-tools";
|