@marko/language-server 1.0.15 → 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 +108 -45
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +108 -45
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -754,73 +754,136 @@ 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
|
-
|
|
776
|
-
}
|
|
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
777
|
}
|
|
778
778
|
}
|
|
779
|
-
);
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
if (!message)
|
|
784
|
-
return;
|
|
785
|
-
const { loc } = err;
|
|
786
|
-
diagnostics.push({
|
|
787
|
-
range: {
|
|
779
|
+
});
|
|
780
|
+
if (meta.diagnostics) {
|
|
781
|
+
for (const diag of meta.diagnostics) {
|
|
782
|
+
const range = diag.loc ? {
|
|
788
783
|
start: {
|
|
789
|
-
line: loc.start.line - 1,
|
|
790
|
-
character: loc.start.column
|
|
784
|
+
line: diag.loc.start.line - 1,
|
|
785
|
+
character: diag.loc.start.column
|
|
791
786
|
},
|
|
792
787
|
end: {
|
|
793
|
-
line: loc.end.line - 1,
|
|
794
|
-
character: loc.end.column
|
|
788
|
+
line: diag.loc.end.line - 1,
|
|
789
|
+
character: diag.loc.end.column
|
|
795
790
|
}
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
tags: void 0,
|
|
800
|
-
severity: DiagnosticSeverity.Error,
|
|
801
|
-
message
|
|
802
|
-
});
|
|
803
|
-
} else {
|
|
804
|
-
let match;
|
|
805
|
-
while (match = markoErrorRegExp.exec(err.message)) {
|
|
806
|
-
const [, , rawLine, rawCol, message] = match;
|
|
807
|
-
const pos = {
|
|
808
|
-
line: (parseInt(rawLine, 10) || 1) - 1,
|
|
809
|
-
character: (parseInt(rawCol, 10) || 1) - 1
|
|
791
|
+
} : {
|
|
792
|
+
start: { line: 0, character: 0 },
|
|
793
|
+
end: { line: 0, character: 0 }
|
|
810
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;
|
|
807
|
+
}
|
|
811
808
|
diagnostics.push({
|
|
812
|
-
range
|
|
809
|
+
range,
|
|
813
810
|
source: "marko",
|
|
814
811
|
code: void 0,
|
|
815
812
|
tags: void 0,
|
|
816
|
-
severity
|
|
817
|
-
message
|
|
813
|
+
severity,
|
|
814
|
+
message: diag.label
|
|
818
815
|
});
|
|
819
816
|
}
|
|
820
817
|
}
|
|
818
|
+
} catch (err) {
|
|
819
|
+
addDiagnosticsForError(err, diagnostics);
|
|
821
820
|
}
|
|
822
821
|
return diagnostics;
|
|
823
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 {
|
|
863
|
+
let match;
|
|
864
|
+
while (match = markoErrorRegExp.exec(err.message)) {
|
|
865
|
+
const [, , rawLine, rawCol, message] = match;
|
|
866
|
+
const pos = {
|
|
867
|
+
line: (parseInt(rawLine, 10) || 1) - 1,
|
|
868
|
+
character: (parseInt(rawCol, 10) || 1) - 1
|
|
869
|
+
};
|
|
870
|
+
diagnostics.push({
|
|
871
|
+
range: { start: pos, end: pos },
|
|
872
|
+
source: "marko",
|
|
873
|
+
code: void 0,
|
|
874
|
+
tags: void 0,
|
|
875
|
+
severity: DiagnosticSeverity.Error,
|
|
876
|
+
message
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
}
|
|
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
|
+
}
|
|
824
887
|
function isErrorWithLoc(err) {
|
|
825
888
|
const loc = err == null ? void 0 : err.loc;
|
|
826
889
|
if (typeof loc !== "object")
|