@mirascript/monaco 0.1.87 → 0.1.89
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/basic/highlighter-manager.d.ts +7 -0
- package/dist/basic/highlighter-manager.d.ts.map +1 -0
- package/dist/basic/index.js +2 -2
- package/dist/basic/language-configuration.d.ts.map +1 -1
- package/dist/basic/textmate-to-monaco.d.ts +3 -0
- package/dist/basic/textmate-to-monaco.d.ts.map +1 -0
- package/dist/basic/tokens-provider.d.ts.map +1 -1
- package/dist/{chunk-JOHUNWDB.js → chunk-HULIQQS3.js} +6 -2
- package/dist/{chunk-JOHUNWDB.js.map → chunk-HULIQQS3.js.map} +1 -1
- package/dist/{chunk-6QSF4YTT.js → chunk-NW3ZHO3C.js} +70 -91
- package/dist/chunk-NW3ZHO3C.js.map +6 -0
- package/dist/contribute.d.ts +5 -1
- package/dist/contribute.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/lsp/index.d.ts +1 -1
- package/dist/lsp/index.d.ts.map +1 -1
- package/dist/lsp/index.js +252 -241
- package/dist/lsp/index.js.map +3 -3
- package/dist/lsp/providers/completion-item-provider/common-global-suggestions.d.ts +5 -0
- package/dist/lsp/providers/completion-item-provider/common-global-suggestions.d.ts.map +1 -0
- package/dist/lsp/providers/completion-item-provider/complete-fields.d.ts +5 -0
- package/dist/lsp/providers/completion-item-provider/complete-fields.d.ts.map +1 -0
- package/dist/lsp/providers/completion-item-provider/complete-global.d.ts +5 -0
- package/dist/lsp/providers/completion-item-provider/complete-global.d.ts.map +1 -0
- package/dist/lsp/providers/completion-item-provider/complete-local.d.ts +5 -0
- package/dist/lsp/providers/completion-item-provider/complete-local.d.ts.map +1 -0
- package/dist/lsp/providers/{completion-item-provider.d.ts → completion-item-provider/index.d.ts} +3 -11
- package/dist/lsp/providers/completion-item-provider/index.d.ts.map +1 -0
- package/dist/lsp/providers/completion-item-provider/interface.d.ts +16 -0
- package/dist/lsp/providers/completion-item-provider/interface.d.ts.map +1 -0
- package/dist/lsp/providers/completion-item-provider/utils.d.ts +11 -0
- package/dist/lsp/providers/completion-item-provider/utils.d.ts.map +1 -0
- package/dist/lsp/utils.d.ts +0 -2
- package/dist/lsp/utils.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/basic/highlighter-manager.ts +38 -0
- package/src/basic/language-configuration.ts +16 -13
- package/src/basic/textmate-to-monaco.ts +49 -0
- package/src/basic/tokens-provider.ts +18 -127
- package/src/contribute.ts +5 -1
- package/src/index.ts +6 -6
- package/src/lsp/index.ts +1 -1
- package/src/lsp/providers/completion-item-provider/common-global-suggestions.ts +155 -0
- package/src/lsp/providers/completion-item-provider/complete-fields.ts +64 -0
- package/src/lsp/providers/completion-item-provider/complete-global.ts +82 -0
- package/src/lsp/providers/completion-item-provider/complete-local.ts +57 -0
- package/src/lsp/providers/completion-item-provider/index.ts +141 -0
- package/src/lsp/providers/completion-item-provider/interface.ts +17 -0
- package/src/lsp/providers/completion-item-provider/utils.ts +61 -0
- package/src/lsp/utils.ts +0 -13
- package/dist/chunk-6QSF4YTT.js.map +0 -6
- package/dist/lsp/providers/completion-item-provider.d.ts.map +0 -1
- package/src/lsp/providers/completion-item-provider.ts +0 -536
package/dist/lsp/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
REG_ORDINAL_FULL,
|
|
9
9
|
RESERVED_KEYWORDS,
|
|
10
10
|
isKeyword
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-NW3ZHO3C.js";
|
|
12
12
|
import {
|
|
13
13
|
Emitter,
|
|
14
14
|
MarkerSeverity,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
Uri,
|
|
19
19
|
editor,
|
|
20
20
|
languages
|
|
21
|
-
} from "../chunk-
|
|
21
|
+
} from "../chunk-HULIQQS3.js";
|
|
22
22
|
|
|
23
23
|
// src/lsp/providers/base.ts
|
|
24
24
|
import { DefaultVmContext } from "@mirascript/mirascript/subtle";
|
|
@@ -822,17 +822,6 @@ function getField(obj, key) {
|
|
|
822
822
|
return void 0;
|
|
823
823
|
}
|
|
824
824
|
}
|
|
825
|
-
function listFields(obj, includeNonEnumerable) {
|
|
826
|
-
if (obj == null || typeof obj != "object") return [];
|
|
827
|
-
if (isVmWrapper(obj)) {
|
|
828
|
-
try {
|
|
829
|
-
return obj.keys(includeNonEnumerable);
|
|
830
|
-
} catch {
|
|
831
|
-
return [];
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
return lib.keys(obj);
|
|
835
|
-
}
|
|
836
825
|
function isDeprecatedGlobal(globals, name) {
|
|
837
826
|
if (!globals.has(name)) {
|
|
838
827
|
return void 0;
|
|
@@ -1563,19 +1552,21 @@ var ColorProvider = class extends Provider {
|
|
|
1563
1552
|
}
|
|
1564
1553
|
};
|
|
1565
1554
|
|
|
1566
|
-
// src/lsp/providers/completion-item-provider.ts
|
|
1567
|
-
import {
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
isVmModule as isVmModule2,
|
|
1571
|
-
isVmWrapper as isVmWrapper2,
|
|
1572
|
-
serialize as serialize2
|
|
1573
|
-
} from "@mirascript/mirascript";
|
|
1574
|
-
import { DiagnosticCode as DiagnosticCode7 } from "@mirascript/mirascript/subtle";
|
|
1555
|
+
// src/lsp/providers/completion-item-provider/index.ts
|
|
1556
|
+
import { DiagnosticCode as DiagnosticCode8 } from "@mirascript/mirascript/subtle";
|
|
1557
|
+
|
|
1558
|
+
// src/lsp/providers/completion-item-provider/common-global-suggestions.ts
|
|
1575
1559
|
import { KEYWORDS as HELP_KEYWORDS } from "@mirascript/help";
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1560
|
+
function kwSuggestion(kw, range) {
|
|
1561
|
+
const doc = HELP_KEYWORDS[kw];
|
|
1562
|
+
return {
|
|
1563
|
+
label: kw,
|
|
1564
|
+
kind: languages.CompletionItemKind.Keyword,
|
|
1565
|
+
insertText: kw,
|
|
1566
|
+
documentation: doc ? { value: doc } : void 0,
|
|
1567
|
+
range
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1579
1570
|
var SUGGEST_KEYWORDS = [];
|
|
1580
1571
|
var loadSuggestKeywords = () => {
|
|
1581
1572
|
if (SUGGEST_KEYWORDS.length > 0) return SUGGEST_KEYWORDS;
|
|
@@ -1707,16 +1698,9 @@ var COMMON_GLOBAL_SUGGESTIONS = (range, extension) => {
|
|
|
1707
1698
|
}
|
|
1708
1699
|
return suggestions;
|
|
1709
1700
|
};
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
label: kw,
|
|
1714
|
-
kind: languages.CompletionItemKind.Keyword,
|
|
1715
|
-
insertText: kw,
|
|
1716
|
-
documentation: doc ? { value: doc } : void 0,
|
|
1717
|
-
range
|
|
1718
|
-
};
|
|
1719
|
-
}
|
|
1701
|
+
|
|
1702
|
+
// src/lsp/providers/completion-item-provider/utils.ts
|
|
1703
|
+
import { getVmFunctionInfo as getVmFunctionInfo2, isVmExtern as isVmExtern2, isVmModule as isVmModule2 } from "@mirascript/mirascript";
|
|
1720
1704
|
function filterText(key, char) {
|
|
1721
1705
|
if (char == null || key.startsWith(char)) return key;
|
|
1722
1706
|
if (key.startsWith("@")) return key.replace(/^@+/, "");
|
|
@@ -1754,147 +1738,174 @@ function completion(model, description, key, value, fn, field) {
|
|
|
1754
1738
|
isField: field
|
|
1755
1739
|
};
|
|
1756
1740
|
}
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1741
|
+
function toCompletionItemRanges(position, range) {
|
|
1742
|
+
return {
|
|
1743
|
+
replace: range,
|
|
1744
|
+
insert: Range.fromPositions(Range.getStartPosition(range), position)
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
// src/lsp/providers/completion-item-provider/complete-fields.ts
|
|
1749
|
+
import { isVmWrapper as isVmWrapper2 } from "@mirascript/mirascript";
|
|
1750
|
+
import { lib as lib2 } from "@mirascript/mirascript/subtle";
|
|
1751
|
+
|
|
1752
|
+
// src/lsp/providers/completion-item-provider/interface.ts
|
|
1753
|
+
var DESC_GLOBAL = "(global)";
|
|
1754
|
+
var DESC_LOCAL = "(local)";
|
|
1755
|
+
var DESC_FIELD = "(field)";
|
|
1756
|
+
|
|
1757
|
+
// src/lsp/providers/completion-item-provider/complete-fields.ts
|
|
1758
|
+
function listFields(obj, includeNonEnumerable) {
|
|
1759
|
+
if (obj == null || typeof obj != "object") return [];
|
|
1760
|
+
if (isVmWrapper2(obj)) {
|
|
1761
|
+
try {
|
|
1762
|
+
return obj.keys(includeNonEnumerable);
|
|
1763
|
+
} catch {
|
|
1764
|
+
return [];
|
|
1765
|
+
}
|
|
1761
1766
|
}
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1767
|
+
return lib2.keys(obj);
|
|
1768
|
+
}
|
|
1769
|
+
async function completeFields(model, position, char, range) {
|
|
1770
|
+
const compiled = await Provider.getCompileResult(model);
|
|
1771
|
+
if (!compiled) return [];
|
|
1772
|
+
const access = compiled.fieldAccessAt(model, position);
|
|
1773
|
+
if (!access || access.fields.length === 0) return [];
|
|
1774
|
+
const { def, fields } = access;
|
|
1775
|
+
if ("definition" in def.def) {
|
|
1776
|
+
return [];
|
|
1777
|
+
}
|
|
1778
|
+
const vmGlobal = await Provider.getContext(model);
|
|
1779
|
+
fields.pop();
|
|
1780
|
+
const [, value] = getDeep(vmGlobal, def.def.name, fields);
|
|
1781
|
+
if (value == null || typeof value != "object") {
|
|
1782
|
+
return [];
|
|
1783
|
+
}
|
|
1784
|
+
const keys = listFields(value, true);
|
|
1785
|
+
const result = [];
|
|
1786
|
+
for (const k of keys) {
|
|
1787
|
+
const key = String(k);
|
|
1788
|
+
if (char && !String(key).toLowerCase().includes(char)) {
|
|
1789
|
+
continue;
|
|
1790
|
+
}
|
|
1791
|
+
if (!REG_IDENTIFIER_FULL.test(key) && !REG_ORDINAL_FULL.test(key)) {
|
|
1792
|
+
continue;
|
|
1793
|
+
}
|
|
1794
|
+
const field = getField(value, key);
|
|
1795
|
+
result.push({
|
|
1796
|
+
insertText: key,
|
|
1797
|
+
range,
|
|
1798
|
+
vmParent: isVmWrapper2(value) ? value : void 0,
|
|
1799
|
+
...completion(model, DESC_FIELD, key, field, void 0, true)
|
|
1800
|
+
});
|
|
1801
|
+
}
|
|
1802
|
+
return result;
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
// src/lsp/providers/completion-item-provider/complete-global.ts
|
|
1806
|
+
import { isVmModule as isVmModule3, serialize as serialize2 } from "@mirascript/mirascript";
|
|
1807
|
+
async function completeGlobal(model, char, locals, range, hasGlobalPrefix) {
|
|
1808
|
+
const global = await Provider.getContext(model);
|
|
1809
|
+
const suggestions = [];
|
|
1810
|
+
const localKeys = new Set(locals.map((item) => item.insertText));
|
|
1811
|
+
for (const key of new Set(global.keys())) {
|
|
1812
|
+
if (!global.has(key) || isDeprecatedGlobal(global, key)) continue;
|
|
1813
|
+
const element = global.get(key);
|
|
1814
|
+
let prefix = key;
|
|
1815
|
+
const edits = [];
|
|
1816
|
+
if (!REG_IDENTIFIER_FULL.test(key)) {
|
|
1817
|
+
const kStr = serialize2(key);
|
|
1818
|
+
if (hasGlobalPrefix) {
|
|
1819
|
+
prefix = `[${kStr}]`;
|
|
1820
|
+
edits.push({
|
|
1821
|
+
range: {
|
|
1822
|
+
startLineNumber: range.replace.startLineNumber,
|
|
1823
|
+
startColumn: range.replace.startColumn - 1,
|
|
1824
|
+
endLineNumber: range.replace.endLineNumber,
|
|
1825
|
+
endColumn: range.replace.endColumn
|
|
1826
|
+
},
|
|
1827
|
+
text: ""
|
|
1828
|
+
});
|
|
1829
|
+
} else {
|
|
1830
|
+
prefix = `global[${serialize2(key)}]`;
|
|
1813
1831
|
}
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
filterText: filterText(key, char),
|
|
1817
|
-
range,
|
|
1818
|
-
additionalTextEdits: edits,
|
|
1819
|
-
vmParent: global,
|
|
1820
|
-
...completion(model, DESC_GLOBAL, key, element, void 0, false)
|
|
1821
|
-
});
|
|
1832
|
+
} else if (!hasGlobalPrefix && (localKeys.has(key) || isKeyword(key))) {
|
|
1833
|
+
prefix = `global.${key}`;
|
|
1822
1834
|
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
const compiled = await this.getCompileResult(model);
|
|
1828
|
-
if (!compiled) return [];
|
|
1829
|
-
const suggestions = [];
|
|
1830
|
-
let scope = compiled.scopeAt(model, position);
|
|
1831
|
-
const locals = /* @__PURE__ */ new Set();
|
|
1832
|
-
while (scope) {
|
|
1833
|
-
for (const { definition, fn } of scope.locals) {
|
|
1834
|
-
const name = definition.code === DiagnosticCode7.ParameterIt ? "it" : model.getValueInRange(definition.range);
|
|
1835
|
-
if (char && !name.toLowerCase().includes(char)) continue;
|
|
1836
|
-
if (locals.has(name)) continue;
|
|
1837
|
-
locals.add(name);
|
|
1838
|
-
const suggestion = {
|
|
1839
|
-
insertText: name,
|
|
1840
|
-
filterText: filterText(name, char),
|
|
1841
|
-
range,
|
|
1842
|
-
...completion(model, DESC_LOCAL, name, void 0, fn, false)
|
|
1843
|
-
};
|
|
1844
|
-
if (definition.code === DiagnosticCode7.LocalModule) {
|
|
1845
|
-
suggestion.kind = languages.CompletionItemKind.Module;
|
|
1846
|
-
} else if (definition.code === DiagnosticCode7.LocalFunction) {
|
|
1847
|
-
suggestion.kind = languages.CompletionItemKind.Function;
|
|
1835
|
+
if (isVmModule3(element)) {
|
|
1836
|
+
for (const f of element.keys()) {
|
|
1837
|
+
if (char && !f.toLowerCase().includes(char)) {
|
|
1838
|
+
continue;
|
|
1848
1839
|
}
|
|
1849
|
-
|
|
1840
|
+
const field = element.get(f);
|
|
1841
|
+
if (field === void 0) continue;
|
|
1842
|
+
suggestions.push({
|
|
1843
|
+
insertText: `${prefix}.${f}`,
|
|
1844
|
+
filterText: filterText(f, char),
|
|
1845
|
+
range,
|
|
1846
|
+
additionalTextEdits: edits,
|
|
1847
|
+
vmParent: element,
|
|
1848
|
+
...completion(model, DESC_GLOBAL, `${key}.${f}`, field, void 0, true)
|
|
1849
|
+
});
|
|
1850
1850
|
}
|
|
1851
|
-
if (!scope.parent) break;
|
|
1852
|
-
scope = scope.parent;
|
|
1853
1851
|
}
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
/** 查找变量字段 */
|
|
1857
|
-
async completeFields(model, position, char, range) {
|
|
1858
|
-
const compiled = await this.getCompileResult(model);
|
|
1859
|
-
if (!compiled) return [];
|
|
1860
|
-
const access = compiled.fieldAccessAt(model, position);
|
|
1861
|
-
if (!access || access.fields.length === 0) return [];
|
|
1862
|
-
const { def, fields } = access;
|
|
1863
|
-
if ("definition" in def.def) {
|
|
1864
|
-
return [];
|
|
1865
|
-
}
|
|
1866
|
-
const vmGlobal = await this.getContext(model);
|
|
1867
|
-
fields.pop();
|
|
1868
|
-
const [, value] = getDeep(vmGlobal, def.def.name, fields);
|
|
1869
|
-
if (value == null || typeof value != "object") {
|
|
1870
|
-
return [];
|
|
1852
|
+
if (char && !key.toLowerCase().includes(char)) {
|
|
1853
|
+
continue;
|
|
1871
1854
|
}
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
continue;
|
|
1881
|
-
}
|
|
1882
|
-
const field = getField(value, key);
|
|
1883
|
-
result.push({
|
|
1884
|
-
insertText: key,
|
|
1885
|
-
range,
|
|
1886
|
-
vmParent: isVmWrapper2(value) ? value : void 0,
|
|
1887
|
-
...completion(model, DESC_FIELD, key, field, void 0, true)
|
|
1888
|
-
});
|
|
1889
|
-
}
|
|
1890
|
-
return result;
|
|
1855
|
+
suggestions.push({
|
|
1856
|
+
insertText: prefix,
|
|
1857
|
+
filterText: filterText(key, char),
|
|
1858
|
+
range,
|
|
1859
|
+
additionalTextEdits: edits,
|
|
1860
|
+
vmParent: global,
|
|
1861
|
+
...completion(model, DESC_GLOBAL, key, element, void 0, false)
|
|
1862
|
+
});
|
|
1891
1863
|
}
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1864
|
+
return suggestions;
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
// src/lsp/providers/completion-item-provider/complete-local.ts
|
|
1868
|
+
import { DiagnosticCode as DiagnosticCode7 } from "@mirascript/mirascript/subtle";
|
|
1869
|
+
function createLocalCompletionItem(model, char, range, locals, { definition, fn }) {
|
|
1870
|
+
const name = definition.code === DiagnosticCode7.ParameterIt ? "it" : model.getValueInRange(definition.range);
|
|
1871
|
+
if (char && !name.toLowerCase().includes(char)) return null;
|
|
1872
|
+
if (locals.has(name)) return null;
|
|
1873
|
+
locals.add(name);
|
|
1874
|
+
const suggestion = {
|
|
1875
|
+
insertText: name,
|
|
1876
|
+
filterText: filterText(name, char),
|
|
1877
|
+
range,
|
|
1878
|
+
...completion(model, DESC_LOCAL, name, void 0, fn, false)
|
|
1879
|
+
};
|
|
1880
|
+
if (definition.code === DiagnosticCode7.LocalModule) {
|
|
1881
|
+
suggestion.kind = languages.CompletionItemKind.Module;
|
|
1882
|
+
} else if (definition.code === DiagnosticCode7.LocalFunction) {
|
|
1883
|
+
suggestion.kind = languages.CompletionItemKind.Function;
|
|
1884
|
+
}
|
|
1885
|
+
return suggestion;
|
|
1886
|
+
}
|
|
1887
|
+
async function completeLocal(model, position, char, range) {
|
|
1888
|
+
const compiled = await Provider.getCompileResult(model);
|
|
1889
|
+
if (!compiled) return [];
|
|
1890
|
+
const suggestions = [];
|
|
1891
|
+
let scope = compiled.scopeAt(model, position);
|
|
1892
|
+
const locals = /* @__PURE__ */ new Set();
|
|
1893
|
+
while (scope) {
|
|
1894
|
+
for (const def of scope.locals) {
|
|
1895
|
+
const suggestion = createLocalCompletionItem(model, char, range, locals, def);
|
|
1896
|
+
if (suggestion) suggestions.push(suggestion);
|
|
1897
|
+
}
|
|
1898
|
+
if (!scope.parent) break;
|
|
1899
|
+
scope = scope.parent;
|
|
1900
|
+
}
|
|
1901
|
+
return suggestions;
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
// src/lsp/providers/completion-item-provider/index.ts
|
|
1905
|
+
var CompletionItemProvider = class extends Provider {
|
|
1906
|
+
constructor() {
|
|
1907
|
+
super(...arguments);
|
|
1908
|
+
this.triggerCharacters = [".", ":"];
|
|
1898
1909
|
}
|
|
1899
1910
|
/** @inheritdoc */
|
|
1900
1911
|
async provideCompletionItems(model, position, context, token) {
|
|
@@ -1906,11 +1917,11 @@ var CompletionItemProvider = class extends Provider {
|
|
|
1906
1917
|
column: position.column - 1
|
|
1907
1918
|
});
|
|
1908
1919
|
if (prevWord?.word === "global") {
|
|
1909
|
-
const globals2 = await
|
|
1920
|
+
const globals2 = await completeGlobal(
|
|
1910
1921
|
model,
|
|
1911
1922
|
void 0,
|
|
1912
1923
|
[],
|
|
1913
|
-
|
|
1924
|
+
toCompletionItemRanges(position, {
|
|
1914
1925
|
startLineNumber: position.lineNumber,
|
|
1915
1926
|
startColumn: position.column,
|
|
1916
1927
|
endLineNumber: position.lineNumber,
|
|
@@ -1938,11 +1949,11 @@ var CompletionItemProvider = class extends Provider {
|
|
|
1938
1949
|
if (def.ref == null) {
|
|
1939
1950
|
const suggestions2 = [];
|
|
1940
1951
|
if (word && compiled.tags.some(
|
|
1941
|
-
(t) => strictContainsPosition(t.range, position) && t.code ===
|
|
1952
|
+
(t) => strictContainsPosition(t.range, position) && t.code === DiagnosticCode8.MatchExpression
|
|
1942
1953
|
)) {
|
|
1943
1954
|
suggestions2.push(
|
|
1944
|
-
kwSuggestion("case",
|
|
1945
|
-
kwSuggestion("if",
|
|
1955
|
+
kwSuggestion("case", toCompletionItemRanges(position, word.range)),
|
|
1956
|
+
kwSuggestion("if", toCompletionItemRanges(position, word.range))
|
|
1946
1957
|
);
|
|
1947
1958
|
}
|
|
1948
1959
|
return { suggestions: suggestions2 };
|
|
@@ -1967,14 +1978,14 @@ var CompletionItemProvider = class extends Provider {
|
|
|
1967
1978
|
};
|
|
1968
1979
|
}
|
|
1969
1980
|
char = char?.toLowerCase();
|
|
1970
|
-
const completionRange =
|
|
1981
|
+
const completionRange = toCompletionItemRanges(position, range);
|
|
1971
1982
|
if (/[^.]\.$/u.test(prev)) {
|
|
1972
|
-
const suggestions2 = await
|
|
1983
|
+
const suggestions2 = await completeFields(model, position, char, completionRange);
|
|
1973
1984
|
return { suggestions: suggestions2 };
|
|
1974
1985
|
}
|
|
1975
1986
|
const suggestions = COMMON_GLOBAL_SUGGESTIONS(completionRange, prev === "::");
|
|
1976
|
-
const locals = await
|
|
1977
|
-
const globals = await
|
|
1987
|
+
const locals = await completeLocal(model, position, char, completionRange);
|
|
1988
|
+
const globals = await completeGlobal(model, char, locals, completionRange, false);
|
|
1978
1989
|
suggestions.push(...locals, ...globals);
|
|
1979
1990
|
return { suggestions };
|
|
1980
1991
|
}
|
|
@@ -2115,7 +2126,7 @@ var DefinitionReferenceProvider = class extends Provider {
|
|
|
2115
2126
|
};
|
|
2116
2127
|
|
|
2117
2128
|
// src/lsp/providers/document-highlight-provider.ts
|
|
2118
|
-
import { DiagnosticCode as
|
|
2129
|
+
import { DiagnosticCode as DiagnosticCode9 } from "@mirascript/mirascript/subtle";
|
|
2119
2130
|
var DocumentHighlightProvider = class extends Provider {
|
|
2120
2131
|
/** @inheritdoc */
|
|
2121
2132
|
async provideDocumentHighlights(model, position, token) {
|
|
@@ -2135,7 +2146,7 @@ var DocumentHighlightProvider = class extends Provider {
|
|
|
2135
2146
|
const links = def.references.map((u) => {
|
|
2136
2147
|
const { code, range } = u;
|
|
2137
2148
|
let kind = languages.DocumentHighlightKind.Read;
|
|
2138
|
-
if (code ===
|
|
2149
|
+
if (code === DiagnosticCode9.WriteLocal || code === DiagnosticCode9.ReadWriteLocal || code === DiagnosticCode9.RedeclareLocal) {
|
|
2139
2150
|
kind = languages.DocumentHighlightKind.Write;
|
|
2140
2151
|
}
|
|
2141
2152
|
return {
|
|
@@ -2165,7 +2176,7 @@ var DocumentHighlightProvider = class extends Provider {
|
|
|
2165
2176
|
};
|
|
2166
2177
|
|
|
2167
2178
|
// src/lsp/providers/document-symbol-provider.ts
|
|
2168
|
-
import { DiagnosticCode as
|
|
2179
|
+
import { DiagnosticCode as DiagnosticCode10 } from "@mirascript/constants";
|
|
2169
2180
|
var DocumentSymbolProvider = class extends Provider {
|
|
2170
2181
|
/** 构建树 */
|
|
2171
2182
|
handleScope(model, scope) {
|
|
@@ -2178,13 +2189,13 @@ var DocumentSymbolProvider = class extends Provider {
|
|
|
2178
2189
|
let children = [];
|
|
2179
2190
|
let allRange = range;
|
|
2180
2191
|
switch (definition.code) {
|
|
2181
|
-
case
|
|
2192
|
+
case DiagnosticCode10.ParameterIt:
|
|
2182
2193
|
if (definition.references.length === 0) {
|
|
2183
2194
|
continue;
|
|
2184
2195
|
}
|
|
2185
2196
|
name = `it`;
|
|
2186
2197
|
break;
|
|
2187
|
-
case
|
|
2198
|
+
case DiagnosticCode10.LocalFunction: {
|
|
2188
2199
|
kind = languages.SymbolKind.Function;
|
|
2189
2200
|
const funcScope = scope.children.find((s) => Range.compareRangesUsingStarts(s.range, range) > 0);
|
|
2190
2201
|
if (funcScope) {
|
|
@@ -2270,7 +2281,7 @@ var FormatterProvider = class extends Provider {
|
|
|
2270
2281
|
};
|
|
2271
2282
|
|
|
2272
2283
|
// src/lsp/providers/hover-provider.ts
|
|
2273
|
-
import { DiagnosticCode as
|
|
2284
|
+
import { DiagnosticCode as DiagnosticCode11 } from "@mirascript/constants";
|
|
2274
2285
|
import { convert } from "@mirascript/mirascript/subtle";
|
|
2275
2286
|
import { KEYWORDS as HELP_KEYWORDS2, OPERATORS as HELP_OPERATORS } from "@mirascript/help";
|
|
2276
2287
|
|
|
@@ -2344,18 +2355,18 @@ function operatorAt(lineContent, column) {
|
|
|
2344
2355
|
return void 0;
|
|
2345
2356
|
}
|
|
2346
2357
|
var LOCAL_HOVER = {
|
|
2347
|
-
[
|
|
2348
|
-
[
|
|
2349
|
-
[
|
|
2350
|
-
[
|
|
2351
|
-
[
|
|
2352
|
-
[
|
|
2353
|
-
[
|
|
2354
|
-
[
|
|
2355
|
-
[
|
|
2356
|
-
[
|
|
2357
|
-
[
|
|
2358
|
-
[
|
|
2358
|
+
[DiagnosticCode11.ParameterSubPatternImmutable]: "(parameter pattern) ",
|
|
2359
|
+
[DiagnosticCode11.ParameterSubPatternMutable]: "(parameter pattern) mut ",
|
|
2360
|
+
[DiagnosticCode11.ParameterImmutable]: "(parameter) ",
|
|
2361
|
+
[DiagnosticCode11.ParameterMutable]: "(parameter) mut ",
|
|
2362
|
+
[DiagnosticCode11.ParameterIt]: "(parameter) it",
|
|
2363
|
+
[DiagnosticCode11.ParameterImmutableRest]: "(parameter) ..",
|
|
2364
|
+
[DiagnosticCode11.ParameterMutableRest]: "(parameter) ..mut ",
|
|
2365
|
+
[DiagnosticCode11.LocalModule]: "mod ",
|
|
2366
|
+
[DiagnosticCode11.LocalImmutable]: "let ",
|
|
2367
|
+
[DiagnosticCode11.LocalConst]: "const ",
|
|
2368
|
+
[DiagnosticCode11.LocalMutable]: "let mut ",
|
|
2369
|
+
[DiagnosticCode11.LocalFunction]: (text, model, def) => {
|
|
2359
2370
|
return `fn ${text}${paramsList(model, def.fn)}`;
|
|
2360
2371
|
}
|
|
2361
2372
|
};
|
|
@@ -2498,7 +2509,7 @@ var HoverProvider = class extends Provider {
|
|
|
2498
2509
|
};
|
|
2499
2510
|
|
|
2500
2511
|
// src/lsp/providers/inlay-hints-provider.ts
|
|
2501
|
-
import { DiagnosticCode as
|
|
2512
|
+
import { DiagnosticCode as DiagnosticCode12 } from "@mirascript/constants";
|
|
2502
2513
|
function provideInlayHint(tag, model) {
|
|
2503
2514
|
let lineNumber = 0;
|
|
2504
2515
|
let column = 0;
|
|
@@ -2508,7 +2519,7 @@ function provideInlayHint(tag, model) {
|
|
|
2508
2519
|
let paddingRight = false;
|
|
2509
2520
|
const edits = [];
|
|
2510
2521
|
switch (tag.code) {
|
|
2511
|
-
case
|
|
2522
|
+
case DiagnosticCode12.ParameterIt: {
|
|
2512
2523
|
if (!tag.references.length) {
|
|
2513
2524
|
return null;
|
|
2514
2525
|
}
|
|
@@ -2523,18 +2534,18 @@ function provideInlayHint(tag, model) {
|
|
|
2523
2534
|
});
|
|
2524
2535
|
break;
|
|
2525
2536
|
}
|
|
2526
|
-
case
|
|
2527
|
-
case
|
|
2528
|
-
case
|
|
2529
|
-
case
|
|
2530
|
-
case
|
|
2531
|
-
case
|
|
2532
|
-
case
|
|
2533
|
-
case
|
|
2534
|
-
case
|
|
2535
|
-
case
|
|
2536
|
-
case
|
|
2537
|
-
const index = tag.code -
|
|
2537
|
+
case DiagnosticCode12.UnnamedRecordField0:
|
|
2538
|
+
case DiagnosticCode12.UnnamedRecordField1:
|
|
2539
|
+
case DiagnosticCode12.UnnamedRecordField2:
|
|
2540
|
+
case DiagnosticCode12.UnnamedRecordField3:
|
|
2541
|
+
case DiagnosticCode12.UnnamedRecordField4:
|
|
2542
|
+
case DiagnosticCode12.UnnamedRecordField5:
|
|
2543
|
+
case DiagnosticCode12.UnnamedRecordField6:
|
|
2544
|
+
case DiagnosticCode12.UnnamedRecordField7:
|
|
2545
|
+
case DiagnosticCode12.UnnamedRecordField8:
|
|
2546
|
+
case DiagnosticCode12.UnnamedRecordField9:
|
|
2547
|
+
case DiagnosticCode12.UnnamedRecordFieldN: {
|
|
2548
|
+
const index = tag.code - DiagnosticCode12.UnnamedRecordField0;
|
|
2538
2549
|
if (index > 9) break;
|
|
2539
2550
|
lineNumber = tag.range.startLineNumber;
|
|
2540
2551
|
column = tag.range.startColumn;
|
|
@@ -2543,9 +2554,9 @@ function provideInlayHint(tag, model) {
|
|
|
2543
2554
|
paddingRight = true;
|
|
2544
2555
|
break;
|
|
2545
2556
|
}
|
|
2546
|
-
case
|
|
2557
|
+
case DiagnosticCode12.OmitNamedRecordField: {
|
|
2547
2558
|
const ref = tag.references[0];
|
|
2548
|
-
if (ref?.code !==
|
|
2559
|
+
if (ref?.code !== DiagnosticCode12.OmitNamedRecordFieldName) {
|
|
2549
2560
|
return null;
|
|
2550
2561
|
}
|
|
2551
2562
|
lineNumber = tag.range.startLineNumber;
|
|
@@ -2632,7 +2643,7 @@ var RangeProvider = class extends Provider {
|
|
|
2632
2643
|
};
|
|
2633
2644
|
|
|
2634
2645
|
// src/lsp/providers/rename-provider.ts
|
|
2635
|
-
import { DiagnosticCode as
|
|
2646
|
+
import { DiagnosticCode as DiagnosticCode13 } from "@mirascript/constants";
|
|
2636
2647
|
function provideRenameEditsOmitNameFields(model, compiled, ref, oldName) {
|
|
2637
2648
|
const edits = [];
|
|
2638
2649
|
const { omitNameFields } = compiled.groupedTags(model);
|
|
@@ -2684,7 +2695,7 @@ var RenameProvider = class extends Provider {
|
|
|
2684
2695
|
versionId: compiled.version,
|
|
2685
2696
|
textEdit: {
|
|
2686
2697
|
range: d.def.definition.range,
|
|
2687
|
-
text: d.def.definition.code ===
|
|
2698
|
+
text: d.def.definition.code === DiagnosticCode13.ParameterIt ? `(${newName})` : newName
|
|
2688
2699
|
}
|
|
2689
2700
|
});
|
|
2690
2701
|
oldName = model.getValueInRange(d.def.definition.range);
|
|
@@ -2753,8 +2764,8 @@ var RenameProvider = class extends Provider {
|
|
|
2753
2764
|
};
|
|
2754
2765
|
|
|
2755
2766
|
// src/lsp/providers/semantic-tokens-provider.ts
|
|
2756
|
-
import { isVmFunction as isVmFunction2, isVmModule as
|
|
2757
|
-
import { DiagnosticCode as
|
|
2767
|
+
import { isVmFunction as isVmFunction2, isVmModule as isVmModule4 } from "@mirascript/mirascript";
|
|
2768
|
+
import { DiagnosticCode as DiagnosticCode14, isKeyword as isKeyword2 } from "@mirascript/constants";
|
|
2758
2769
|
var TOKEN_TYPES = {
|
|
2759
2770
|
[0 /* VARIABLE */]: "variable.other.constant",
|
|
2760
2771
|
[1 /* VARIABLE_MUTABLE */]: "variable",
|
|
@@ -2789,7 +2800,7 @@ var DocumentSemanticTokensProvider = class extends Provider {
|
|
|
2789
2800
|
let tokenType = -1;
|
|
2790
2801
|
let onlyReferences = false;
|
|
2791
2802
|
switch (code) {
|
|
2792
|
-
case
|
|
2803
|
+
case DiagnosticCode14.GlobalVariable: {
|
|
2793
2804
|
const id = model.getValueInRange(range);
|
|
2794
2805
|
if (id.startsWith("@")) {
|
|
2795
2806
|
tokenType = 2 /* CONSTANT */;
|
|
@@ -2799,7 +2810,7 @@ var DocumentSemanticTokensProvider = class extends Provider {
|
|
|
2799
2810
|
break;
|
|
2800
2811
|
} else if (isVmFunction2(val)) {
|
|
2801
2812
|
tokenType = 4 /* FUNCTION */;
|
|
2802
|
-
} else if (
|
|
2813
|
+
} else if (isVmModule4(val)) {
|
|
2803
2814
|
tokenType = 5 /* MODULE */;
|
|
2804
2815
|
} else {
|
|
2805
2816
|
tokenType = 3 /* GLOBAL */;
|
|
@@ -2807,50 +2818,50 @@ var DocumentSemanticTokensProvider = class extends Provider {
|
|
|
2807
2818
|
}
|
|
2808
2819
|
break;
|
|
2809
2820
|
}
|
|
2810
|
-
case
|
|
2821
|
+
case DiagnosticCode14.LocalFunction: {
|
|
2811
2822
|
tokenType = 4 /* FUNCTION */;
|
|
2812
2823
|
break;
|
|
2813
2824
|
}
|
|
2814
|
-
case
|
|
2825
|
+
case DiagnosticCode14.LocalModule: {
|
|
2815
2826
|
tokenType = 5 /* MODULE */;
|
|
2816
2827
|
break;
|
|
2817
2828
|
}
|
|
2818
|
-
case
|
|
2819
|
-
case
|
|
2820
|
-
case
|
|
2829
|
+
case DiagnosticCode14.ParameterMutable:
|
|
2830
|
+
case DiagnosticCode14.ParameterSubPatternMutable:
|
|
2831
|
+
case DiagnosticCode14.ParameterMutableRest: {
|
|
2821
2832
|
tokenType = 9 /* PARAM_MUTABLE */;
|
|
2822
2833
|
break;
|
|
2823
2834
|
}
|
|
2824
|
-
case
|
|
2835
|
+
case DiagnosticCode14.LocalMutable: {
|
|
2825
2836
|
tokenType = 1 /* VARIABLE_MUTABLE */;
|
|
2826
2837
|
break;
|
|
2827
2838
|
}
|
|
2828
|
-
case
|
|
2839
|
+
case DiagnosticCode14.ParameterIt: {
|
|
2829
2840
|
tokenType = 8 /* PARAM */;
|
|
2830
2841
|
onlyReferences = true;
|
|
2831
2842
|
break;
|
|
2832
2843
|
}
|
|
2833
|
-
case
|
|
2834
|
-
case
|
|
2835
|
-
case
|
|
2844
|
+
case DiagnosticCode14.ParameterImmutable:
|
|
2845
|
+
case DiagnosticCode14.ParameterSubPatternImmutable:
|
|
2846
|
+
case DiagnosticCode14.ParameterImmutableRest: {
|
|
2836
2847
|
tokenType = 8 /* PARAM */;
|
|
2837
2848
|
break;
|
|
2838
2849
|
}
|
|
2839
|
-
case
|
|
2850
|
+
case DiagnosticCode14.LocalImmutable: {
|
|
2840
2851
|
tokenType = 0 /* VARIABLE */;
|
|
2841
2852
|
break;
|
|
2842
2853
|
}
|
|
2843
|
-
case
|
|
2854
|
+
case DiagnosticCode14.LocalConst: {
|
|
2844
2855
|
tokenType = 2 /* CONSTANT */;
|
|
2845
2856
|
break;
|
|
2846
2857
|
}
|
|
2847
2858
|
// case DiagnosticCode.RecordFieldStringName:
|
|
2848
|
-
case
|
|
2849
|
-
case
|
|
2859
|
+
case DiagnosticCode14.RecordFieldOrdinalName:
|
|
2860
|
+
case DiagnosticCode14.RecordFieldIdName: {
|
|
2850
2861
|
tokenType = 6 /* PROPERTY */;
|
|
2851
2862
|
break;
|
|
2852
2863
|
}
|
|
2853
|
-
case
|
|
2864
|
+
case DiagnosticCode14.ForExpression: {
|
|
2854
2865
|
tokenType = 7 /* KEYWORD_CONTROL */;
|
|
2855
2866
|
onlyReferences = true;
|
|
2856
2867
|
break;
|
|
@@ -2870,7 +2881,7 @@ var DocumentSemanticTokensProvider = class extends Provider {
|
|
|
2870
2881
|
});
|
|
2871
2882
|
}
|
|
2872
2883
|
for (const ref of references) {
|
|
2873
|
-
if (ref.code ===
|
|
2884
|
+
if (ref.code === DiagnosticCode14.ExportedLocal) {
|
|
2874
2885
|
continue;
|
|
2875
2886
|
}
|
|
2876
2887
|
data.push({
|
|
@@ -2912,7 +2923,7 @@ var DocumentSemanticTokensProvider = class extends Provider {
|
|
|
2912
2923
|
};
|
|
2913
2924
|
|
|
2914
2925
|
// src/lsp/providers/signature-help-provider.ts
|
|
2915
|
-
import { DiagnosticCode as
|
|
2926
|
+
import { DiagnosticCode as DiagnosticCode15 } from "@mirascript/constants";
|
|
2916
2927
|
import { getVmFunctionInfo as getVmFunctionInfo3 } from "@mirascript/mirascript";
|
|
2917
2928
|
var SignatureHelpProvider = class extends Provider {
|
|
2918
2929
|
constructor() {
|
|
@@ -2927,14 +2938,14 @@ var SignatureHelpProvider = class extends Provider {
|
|
|
2927
2938
|
const compiled = await this.getCompileResult(model);
|
|
2928
2939
|
if (!compiled) return void 0;
|
|
2929
2940
|
const invokes = compiled.groupedTags(model).ranges.filter((r) => {
|
|
2930
|
-
if (r.code !==
|
|
2941
|
+
if (r.code !== DiagnosticCode15.FunctionCall && r.code !== DiagnosticCode15.ExtensionCall) {
|
|
2931
2942
|
return false;
|
|
2932
2943
|
}
|
|
2933
2944
|
if (!strictContainsPosition(r.range, position)) {
|
|
2934
2945
|
return false;
|
|
2935
2946
|
}
|
|
2936
|
-
const argStart = r.references.find((ref) => ref.code ===
|
|
2937
|
-
const argEnd = r.references.find((ref) => ref.code ===
|
|
2947
|
+
const argStart = r.references.find((ref) => ref.code === DiagnosticCode15.ArgumentStart);
|
|
2948
|
+
const argEnd = r.references.find((ref) => ref.code === DiagnosticCode15.ArgumentEnd);
|
|
2938
2949
|
if (!argStart || !argEnd) {
|
|
2939
2950
|
return false;
|
|
2940
2951
|
}
|
|
@@ -2946,7 +2957,7 @@ var SignatureHelpProvider = class extends Provider {
|
|
|
2946
2957
|
if (!invokes.length) return void 0;
|
|
2947
2958
|
invokes.sort((a, b) => Range.strictContainsRange(a.range, b.range) ? 1 : -1);
|
|
2948
2959
|
const invoke = invokes[0];
|
|
2949
|
-
const callableRef = invoke.references.find((ref) => ref.code ===
|
|
2960
|
+
const callableRef = invoke.references.find((ref) => ref.code === DiagnosticCode15.Callable);
|
|
2950
2961
|
if (!callableRef) return void 0;
|
|
2951
2962
|
const callableInfo = compiled.accessAt(model, Range.getEndPosition(callableRef.range));
|
|
2952
2963
|
if (!callableInfo) return void 0;
|
|
@@ -2970,7 +2981,7 @@ var SignatureHelpProvider = class extends Provider {
|
|
|
2970
2981
|
label: "",
|
|
2971
2982
|
parameters: []
|
|
2972
2983
|
};
|
|
2973
|
-
if (invoke.code ===
|
|
2984
|
+
if (invoke.code === DiagnosticCode15.ExtensionCall) {
|
|
2974
2985
|
const thisArg = sig.params[0];
|
|
2975
2986
|
if (thisArg && !thisArg[0].startsWith("..")) {
|
|
2976
2987
|
sig.params.shift();
|
|
@@ -2999,8 +3010,8 @@ var SignatureHelpProvider = class extends Provider {
|
|
|
2999
3010
|
signature.label += ")" + sig.returns;
|
|
3000
3011
|
let pos = 0;
|
|
3001
3012
|
for (const ref of invoke.references) {
|
|
3002
|
-
if (ref.code ===
|
|
3003
|
-
if (ref.code !==
|
|
3013
|
+
if (ref.code === DiagnosticCode15.ArgumentSpread) pos = Number.NaN;
|
|
3014
|
+
if (ref.code !== DiagnosticCode15.ArgumentComma || Range.isEmpty(ref.range)) continue;
|
|
3004
3015
|
if (Position.isBeforeOrEqual(Range.getEndPosition(ref.range), position) && !sig.params[pos]?.[0].startsWith("..")) {
|
|
3005
3016
|
pos++;
|
|
3006
3017
|
}
|