@innovatorved/code-lab 0.5.0 → 0.6.0
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/ARCHITECTURE.md +3 -3
- package/CHANGELOG.md +15 -0
- package/README.md +3 -3
- package/dist/code-lab-sql.esm.js +1 -1
- package/dist/code-lab-sql.umd.js +2 -2
- package/dist/code-lab.css +32 -7273
- package/dist/code-lab.d.ts +1 -1
- package/dist/code-lab.esm.js +4669 -74678
- package/dist/code-lab.js +4655 -74665
- package/dist/code-lab.umd.js +4655 -74665
- package/dist/extensions/cpp.d.ts +2 -2
- package/dist/extensions/cpp.esm.js +1788 -14707
- package/dist/extensions/cpp.js +1788 -14707
- package/dist/extensions/guided-lab.esm.js +2938 -16127
- package/dist/extensions/guided-lab.js +2938 -16127
- package/dist/extensions/python.d.ts +2 -2
- package/dist/extensions/python.esm.js +1769 -14701
- package/dist/extensions/python.js +1769 -14701
- package/dist/index.d.ts +1 -1
- package/dist/preview-sw.js +4 -188
- package/dist/runtime.esm.js +109 -10284
- package/dist/runtime.js +107 -10284
- package/dist/schemas.d.ts +2 -2
- package/dist/schemas.esm.js +2938 -16127
- package/dist/schemas.js +2941 -16130
- package/dist/scm.d.ts +221 -20
- package/dist/shell.esm.js +811 -10002
- package/dist/shell.js +811 -10002
- package/dist/storage.d.ts +9 -0
- package/dist/terminal.esm.js +20 -1347
- package/dist/terminal.js +20 -1347
- package/dist/workbench/command-palette.d.ts +16 -1
- package/dist/workbench/diff-editor.d.ts +27 -1
- package/dist/workbench/icons.d.ts +6 -2
- package/dist/workbench/index.d.ts +32 -0
- package/dist/workbench/intellisense.d.ts +194 -0
- package/dist/workbench/xterm-adapter.d.ts +122 -0
- package/package.json +7 -1
- package/packages/commands/package.json +1 -1
- package/packages/core/package.json +1 -1
- package/packages/editor/package.json +1 -1
- package/packages/fs/package.json +1 -1
- package/packages/preview/package.json +1 -1
- package/packages/runtime/package.json +1 -1
- package/packages/settings/package.json +1 -1
- package/packages/sql/package.json +1 -1
- package/packages/terminal/package.json +1 -1
- package/packages/ui/package.json +1 -1
- package/packages/ui/src/settings-dialog.ts +36 -24
- package/packages/ui/src/themes.ts +89 -23
- package/src/code-lab.css +1345 -481
- package/src/extensions/cpp.ts +304 -38
- package/src/extensions/python.ts +342 -43
- package/src/index.ts +1 -1
- package/src/runtime.ts +272 -43
- package/src/schemas.ts +2 -2
- package/src/scm.ts +1467 -92
- package/src/shell.ts +1075 -93
- package/src/storage.ts +66 -3
- package/src/terminal.ts +148 -12
- package/src/workbench/command-palette.ts +289 -48
- package/src/workbench/diff-editor.ts +240 -78
- package/src/workbench/icons.ts +250 -53
- package/src/workbench/index.ts +7 -1
- package/src/workbench/intellisense.ts +1859 -0
- package/src/workbench/xterm-adapter.ts +1566 -0
- package/src/workbench.ts +1605 -236
package/src/extensions/cpp.ts
CHANGED
|
@@ -1619,17 +1619,151 @@ export const CPP_COMPLETIONS_AND_HOVERS: Record<string, CppSymbolDoc> = {
|
|
|
1619
1619
|
}
|
|
1620
1620
|
};
|
|
1621
1621
|
|
|
1622
|
-
let
|
|
1622
|
+
let _cppWorkspaceFilesGetter: (() => Record<string, string>) | null = null;
|
|
1623
|
+
const _monacoCppInstances = new WeakSet<object>();
|
|
1624
|
+
|
|
1625
|
+
const CPP_STL_CONTAINER_MEMBERS: Record<string, Array<{ name: string; detail: string; insert?: string; doc: string }>> = {
|
|
1626
|
+
vector: [
|
|
1627
|
+
{ name: 'push_back', detail: 'void push_back(const T& val)', insert: 'push_back(${1:val})', doc: 'Appends an element to the end ($O(1)$ amortized).' },
|
|
1628
|
+
{ name: 'emplace_back', detail: 'T& emplace_back(Args&&... args)', insert: 'emplace_back(${1:args})', doc: 'Constructs an element in-place at the end.' },
|
|
1629
|
+
{ name: 'pop_back', detail: 'void pop_back()', insert: 'pop_back()', doc: 'Removes the last element ($O(1)$).' },
|
|
1630
|
+
{ name: 'size', detail: 'size_t size() const noexcept', insert: 'size()', doc: 'Returns the number of elements.' },
|
|
1631
|
+
{ name: 'empty', detail: 'bool empty() const noexcept', insert: 'empty()', doc: 'Checks whether the container is empty.' },
|
|
1632
|
+
{ name: 'clear', detail: 'void clear() noexcept', insert: 'clear()', doc: 'Clears the contents.' },
|
|
1633
|
+
{ name: 'begin', detail: 'iterator begin() noexcept', insert: 'begin()', doc: 'Returns an iterator to the beginning.' },
|
|
1634
|
+
{ name: 'end', detail: 'iterator end() noexcept', insert: 'end()', doc: 'Returns an iterator to the end.' },
|
|
1635
|
+
{ name: 'front', detail: 'T& front()', insert: 'front()', doc: 'Accesses the first element.' },
|
|
1636
|
+
{ name: 'back', detail: 'T& back()', insert: 'back()', doc: 'Accesses the last element.' },
|
|
1637
|
+
{ name: 'resize', detail: 'void resize(size_t count)', insert: 'resize(${1:n})', doc: 'Resizes the container to contain count elements.' },
|
|
1638
|
+
{ name: 'reserve', detail: 'void reserve(size_t new_cap)', insert: 'reserve(${1:cap})', doc: 'Reserves storage capacity.' }
|
|
1639
|
+
],
|
|
1640
|
+
string: [
|
|
1641
|
+
{ name: 'size', detail: 'size_t size() const noexcept', insert: 'size()', doc: 'Returns character count.' },
|
|
1642
|
+
{ name: 'length', detail: 'size_t length() const noexcept', insert: 'length()', doc: 'Returns character count.' },
|
|
1643
|
+
{ name: 'empty', detail: 'bool empty() const noexcept', insert: 'empty()', doc: 'Returns true if string is empty.' },
|
|
1644
|
+
{ name: 'substr', detail: 'string substr(size_t pos = 0, size_t count = npos) const', insert: 'substr(${1:pos}, ${2:len})', doc: 'Returns a substring.' },
|
|
1645
|
+
{ name: 'find', detail: 'size_t find(const string& str, size_t pos = 0) const', insert: 'find(${1:str})', doc: 'Finds first occurrence of substring or `string::npos`.' },
|
|
1646
|
+
{ name: 'push_back', detail: 'void push_back(char ch)', insert: 'push_back(${1:ch})', doc: 'Appends a character.' },
|
|
1647
|
+
{ name: 'c_str', detail: 'const char* c_str() const noexcept', insert: 'c_str()', doc: 'Returns null-terminated character array.' },
|
|
1648
|
+
{ name: 'begin', detail: 'iterator begin() noexcept', insert: 'begin()', doc: 'Iterator to start.' },
|
|
1649
|
+
{ name: 'end', detail: 'iterator end() noexcept', insert: 'end()', doc: 'Iterator past end.' }
|
|
1650
|
+
],
|
|
1651
|
+
map: [
|
|
1652
|
+
{ name: 'insert', detail: 'pair<iterator, bool> insert(const value_type& value)', insert: 'insert({${1:key}, ${2:val}})', doc: 'Inserts key-value pair.' },
|
|
1653
|
+
{ name: 'emplace', detail: 'pair<iterator, bool> emplace(Args&&... args)', insert: 'emplace(${1:key}, ${2:val})', doc: 'Constructs element in-place.' },
|
|
1654
|
+
{ name: 'find', detail: 'iterator find(const Key& key)', insert: 'find(${1:key})', doc: 'Finds element with specific key.' },
|
|
1655
|
+
{ name: 'count', detail: 'size_t count(const Key& key) const', insert: 'count(${1:key})', doc: 'Returns 1 if key exists, 0 otherwise.' },
|
|
1656
|
+
{ name: 'contains', detail: 'bool contains(const Key& key) const (C++20)', insert: 'contains(${1:key})', doc: 'Checks if there is an element with key (C++20).' },
|
|
1657
|
+
{ name: 'erase', detail: 'size_t erase(const Key& key)', insert: 'erase(${1:key})', doc: 'Removes element by key or iterator.' },
|
|
1658
|
+
{ name: 'size', detail: 'size_t size() const noexcept', insert: 'size()', doc: 'Returns number of entries.' },
|
|
1659
|
+
{ name: 'empty', detail: 'bool empty() const noexcept', insert: 'empty()', doc: 'Checks if container is empty.' },
|
|
1660
|
+
{ name: 'begin', detail: 'iterator begin() noexcept', insert: 'begin()', doc: 'Iterator to first entry.' },
|
|
1661
|
+
{ name: 'end', detail: 'iterator end() noexcept', insert: 'end()', doc: 'Iterator past last entry.' }
|
|
1662
|
+
],
|
|
1663
|
+
set: [
|
|
1664
|
+
{ name: 'insert', detail: 'pair<iterator, bool> insert(const Key& value)', insert: 'insert(${1:val})', doc: 'Inserts element into set.' },
|
|
1665
|
+
{ name: 'find', detail: 'iterator find(const Key& key)', insert: 'find(${1:val})', doc: 'Finds element matching key.' },
|
|
1666
|
+
{ name: 'count', detail: 'size_t count(const Key& key) const', insert: 'count(${1:val})', doc: 'Returns number of matching elements.' },
|
|
1667
|
+
{ name: 'contains', detail: 'bool contains(const Key& key) const (C++20)', insert: 'contains(${1:val})', doc: 'Checks if element exists (C++20).' },
|
|
1668
|
+
{ name: 'erase', detail: 'size_t erase(const Key& key)', insert: 'erase(${1:val})', doc: 'Erases element.' },
|
|
1669
|
+
{ name: 'size', detail: 'size_t size() const noexcept', insert: 'size()', doc: 'Returns size.' },
|
|
1670
|
+
{ name: 'empty', detail: 'bool empty() const noexcept', insert: 'empty()', doc: 'Checks if empty.' }
|
|
1671
|
+
],
|
|
1672
|
+
queue: [
|
|
1673
|
+
{ name: 'push', detail: 'void push(const T& value)', insert: 'push(${1:val})', doc: 'Inserts element at back of queue.' },
|
|
1674
|
+
{ name: 'pop', detail: 'void pop()', insert: 'pop()', doc: 'Removes front/top element.' },
|
|
1675
|
+
{ name: 'front', detail: 'T& front()', insert: 'front()', doc: 'Accesses first element (queue).' },
|
|
1676
|
+
{ name: 'top', detail: 'const T& top() const', insert: 'top()', doc: 'Accesses top element (priority_queue / stack).' },
|
|
1677
|
+
{ name: 'empty', detail: 'bool empty() const', insert: 'empty()', doc: 'Checks whether underlying container is empty.' },
|
|
1678
|
+
{ name: 'size', detail: 'size_t size() const', insert: 'size()', doc: 'Returns number of elements.' }
|
|
1679
|
+
],
|
|
1680
|
+
ListNode: [
|
|
1681
|
+
{ name: 'val', detail: 'int val', insert: 'val', doc: 'Node integer value.' },
|
|
1682
|
+
{ name: 'next', detail: 'ListNode* next', insert: 'next', doc: 'Pointer to next node in singly-linked list.' }
|
|
1683
|
+
],
|
|
1684
|
+
TreeNode: [
|
|
1685
|
+
{ name: 'val', detail: 'int val', insert: 'val', doc: 'Node integer value.' },
|
|
1686
|
+
{ name: 'left', detail: 'TreeNode* left', insert: 'left', doc: 'Left child pointer.' },
|
|
1687
|
+
{ name: 'right', detail: 'TreeNode* right', insert: 'right', doc: 'Right child pointer.' }
|
|
1688
|
+
]
|
|
1689
|
+
};
|
|
1690
|
+
|
|
1691
|
+
function inferCppLocalContainerKind(source: string, ident: string): string | null {
|
|
1692
|
+
const escaped = ident.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1693
|
+
const declRe = new RegExp(`(?:std::)?(unordered_map|map|unordered_set|set|vector|string|priority_queue|queue|stack|ListNode|TreeNode)\\s*(?:<[^;{}=]*>)?\\s*[*&]?\\s*\\b${escaped}\\b`);
|
|
1694
|
+
const m = source.match(declRe);
|
|
1695
|
+
if (!m) return null;
|
|
1696
|
+
const raw = m[1];
|
|
1697
|
+
if (raw === 'unordered_map' || raw === 'map') return 'map';
|
|
1698
|
+
if (raw === 'unordered_set' || raw === 'set') return 'set';
|
|
1699
|
+
if (raw === 'priority_queue' || raw === 'queue' || raw === 'stack') return 'queue';
|
|
1700
|
+
return raw;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
function collectWorkspaceCppSymbols(currentSource: string, currentPath = 'main.cpp') {
|
|
1704
|
+
const files: Record<string, string> = _cppWorkspaceFilesGetter ? { ...(_cppWorkspaceFilesGetter() || {}) } : {};
|
|
1705
|
+
const cleanCurrent = String(currentPath || 'main.cpp').replace(/^file:\/\/\/workspace\//, '').replace(/^\/workspace\//, '').replace(/^\/+/, '') || 'main.cpp';
|
|
1706
|
+
if (currentSource) files[cleanCurrent] = currentSource;
|
|
1707
|
+
|
|
1708
|
+
const symbols: Array<{ name: string; kind: 'function' | 'struct' | 'class'; detail: string; file: string; line: number; col: number; params: string[] }> = [];
|
|
1709
|
+
for (const [filePath, src] of Object.entries(files)) {
|
|
1710
|
+
if (!/\.(?:cpp|cc|cxx|c|h|hpp|hxx)$/i.test(filePath)) continue;
|
|
1711
|
+
const lines = String(src || '').split('\n');
|
|
1712
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1713
|
+
const line = lines[i];
|
|
1714
|
+
const trimmed = line.trim();
|
|
1715
|
+
if (!trimmed || trimmed.startsWith('//') || trimmed.startsWith('#')) continue;
|
|
1716
|
+
const scMatch = line.match(/^\s*(struct|class)\s+([A-Za-z_][A-Za-z0-9_]*)/);
|
|
1717
|
+
if (scMatch) {
|
|
1718
|
+
symbols.push({
|
|
1719
|
+
name: scMatch[2],
|
|
1720
|
+
kind: scMatch[1] as 'struct' | 'class',
|
|
1721
|
+
detail: `${scMatch[1]} ${scMatch[2]}`,
|
|
1722
|
+
file: filePath,
|
|
1723
|
+
line: i + 1,
|
|
1724
|
+
col: line.indexOf(scMatch[2]) + 1,
|
|
1725
|
+
params: []
|
|
1726
|
+
});
|
|
1727
|
+
continue;
|
|
1728
|
+
}
|
|
1729
|
+
const fnMatch = line.match(/^\s*(?:template\s*<[^>]+>\s*)?(?:inline\s+|static\s+|constexpr\s+)*([A-Za-z_][A-Za-z0-9_:<>,&\s*]*?)\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(([^;{}]*)\)\s*(?:const\s*)?(?:noexcept\s*)?[{;]/);
|
|
1730
|
+
if (fnMatch && !/^(?:if|for|while|switch|catch|return)$/.test(fnMatch[2])) {
|
|
1731
|
+
const ret = fnMatch[1].trim();
|
|
1732
|
+
const name = fnMatch[2];
|
|
1733
|
+
const rawParams = fnMatch[3].trim();
|
|
1734
|
+
symbols.push({
|
|
1735
|
+
name,
|
|
1736
|
+
kind: 'function',
|
|
1737
|
+
detail: `${ret} ${name}(${rawParams})`,
|
|
1738
|
+
file: filePath,
|
|
1739
|
+
line: i + 1,
|
|
1740
|
+
col: line.indexOf(name) + 1,
|
|
1741
|
+
params: rawParams ? rawParams.split(',').map((p) => p.trim()).filter(Boolean) : []
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
return symbols;
|
|
1747
|
+
}
|
|
1623
1748
|
|
|
1624
1749
|
/**
|
|
1625
|
-
* Registers Monaco C++20 completion
|
|
1750
|
+
* Registers Monaco C++20 completion, STL member completion, hover, signature help, and definition providers.
|
|
1626
1751
|
*/
|
|
1627
|
-
export function registerMonacoCppLanguageService(
|
|
1752
|
+
export function registerMonacoCppLanguageService(
|
|
1753
|
+
monacoInstance: any,
|
|
1754
|
+
getWorkspaceFiles?: () => Record<string, string>
|
|
1755
|
+
): boolean {
|
|
1756
|
+
if (typeof getWorkspaceFiles === 'function') {
|
|
1757
|
+
_cppWorkspaceFilesGetter = getWorkspaceFiles;
|
|
1758
|
+
}
|
|
1628
1759
|
if (!monacoInstance || !monacoInstance.languages) return false;
|
|
1629
|
-
if (
|
|
1630
|
-
|
|
1760
|
+
if (_monacoCppInstances.has(monacoInstance)) return true;
|
|
1761
|
+
_monacoCppInstances.add(monacoInstance);
|
|
1631
1762
|
|
|
1632
1763
|
try {
|
|
1764
|
+
const CIK = monacoInstance.languages.CompletionItemKind || {};
|
|
1765
|
+
const CITR = monacoInstance.languages.CompletionItemInsertTextRule || {};
|
|
1766
|
+
|
|
1633
1767
|
monacoInstance.languages.registerCompletionItemProvider('cpp', {
|
|
1634
1768
|
triggerCharacters: ['.', ':', '>', '<'],
|
|
1635
1769
|
provideCompletionItems(model: any, position: any) {
|
|
@@ -1640,20 +1774,61 @@ export function registerMonacoCppLanguageService(monacoInstance: any): boolean {
|
|
|
1640
1774
|
startColumn: wordInfo.startColumn,
|
|
1641
1775
|
endColumn: wordInfo.endColumn
|
|
1642
1776
|
};
|
|
1777
|
+
const fullSource = typeof model.getValue === 'function' ? model.getValue() : '';
|
|
1778
|
+
const linePrefix = typeof model.getLineContent === 'function'
|
|
1779
|
+
? String(model.getLineContent(position.lineNumber) || '').slice(0, position.column - 1)
|
|
1780
|
+
: '';
|
|
1781
|
+
|
|
1782
|
+
// Member access `vec.` or `node->`
|
|
1783
|
+
const memberMatch = linePrefix.match(/([A-Za-z_][A-Za-z0-9_]*)\s*(?:\.|->)\s*[A-Za-z0-9_]*$/);
|
|
1784
|
+
if (memberMatch) {
|
|
1785
|
+
const containerKind = inferCppLocalContainerKind(fullSource, memberMatch[1]);
|
|
1786
|
+
const members = containerKind ? CPP_STL_CONTAINER_MEMBERS[containerKind] : null;
|
|
1787
|
+
if (members) {
|
|
1788
|
+
return {
|
|
1789
|
+
suggestions: members.map((m) => ({
|
|
1790
|
+
label: m.name,
|
|
1791
|
+
kind: m.insert?.includes('(') ? (CIK.Method ?? 0) : (CIK.Field ?? 4),
|
|
1792
|
+
detail: m.detail,
|
|
1793
|
+
documentation: { value: m.doc },
|
|
1794
|
+
insertText: m.insert || m.name,
|
|
1795
|
+
insertTextRules: CITR.InsertAsSnippet,
|
|
1796
|
+
range
|
|
1797
|
+
}))
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1643
1801
|
|
|
1802
|
+
const seen = new Set<string>();
|
|
1644
1803
|
const suggestions = Object.keys(CPP_COMPLETIONS_AND_HOVERS).map((key) => {
|
|
1645
1804
|
const item = CPP_COMPLETIONS_AND_HOVERS[key];
|
|
1805
|
+
seen.add(item.label);
|
|
1646
1806
|
return {
|
|
1647
1807
|
label: item.label,
|
|
1648
|
-
kind:
|
|
1808
|
+
kind: CIK.Function ?? 1,
|
|
1649
1809
|
detail: item.detail,
|
|
1650
1810
|
documentation: { value: item.documentation },
|
|
1651
1811
|
insertText: item.insertText || item.label,
|
|
1652
|
-
insertTextRules:
|
|
1812
|
+
insertTextRules: CITR.InsertAsSnippet,
|
|
1653
1813
|
range
|
|
1654
1814
|
};
|
|
1655
1815
|
});
|
|
1656
1816
|
|
|
1817
|
+
const wsSyms = collectWorkspaceCppSymbols(fullSource, model.uri?.path || 'main.cpp');
|
|
1818
|
+
for (const sym of wsSyms) {
|
|
1819
|
+
if (seen.has(sym.name)) continue;
|
|
1820
|
+
seen.add(sym.name);
|
|
1821
|
+
suggestions.push({
|
|
1822
|
+
label: sym.name,
|
|
1823
|
+
kind: sym.kind === 'function' ? (CIK.Function ?? 1) : (CIK.Struct ?? 6),
|
|
1824
|
+
detail: sym.detail,
|
|
1825
|
+
documentation: { value: `Defined in \`${sym.file}:${sym.line}\`` },
|
|
1826
|
+
insertText: sym.kind === 'function' ? `${sym.name}(${sym.params.length ? '$1' : ''})` : sym.name,
|
|
1827
|
+
insertTextRules: CITR.InsertAsSnippet,
|
|
1828
|
+
range
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1657
1832
|
return { suggestions };
|
|
1658
1833
|
}
|
|
1659
1834
|
});
|
|
@@ -1663,27 +1838,70 @@ export function registerMonacoCppLanguageService(monacoInstance: any): boolean {
|
|
|
1663
1838
|
const word = model.getWordAtPosition(position);
|
|
1664
1839
|
if (!word) return null;
|
|
1665
1840
|
|
|
1666
|
-
// Try exact match or std:: + word
|
|
1667
1841
|
const key = CPP_COMPLETIONS_AND_HOVERS[word.word]
|
|
1668
1842
|
? word.word
|
|
1669
1843
|
: (CPP_COMPLETIONS_AND_HOVERS['std::' + word.word] ? 'std::' + word.word : null);
|
|
1670
1844
|
|
|
1671
|
-
if (
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1845
|
+
if (key) {
|
|
1846
|
+
const item = CPP_COMPLETIONS_AND_HOVERS[key];
|
|
1847
|
+
return {
|
|
1848
|
+
range: {
|
|
1849
|
+
startLineNumber: position.lineNumber,
|
|
1850
|
+
endLineNumber: position.lineNumber,
|
|
1851
|
+
startColumn: word.startColumn,
|
|
1852
|
+
endColumn: word.endColumn
|
|
1853
|
+
},
|
|
1854
|
+
contents: [
|
|
1855
|
+
{ value: `**${item.label}** — \`${item.detail}\`` },
|
|
1856
|
+
{ value: item.documentation }
|
|
1857
|
+
]
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
const wsSyms = collectWorkspaceCppSymbols(model.getValue?.() || '', model.uri?.path || 'main.cpp');
|
|
1862
|
+
const wsHit = wsSyms.find((s) => s.name === word.word);
|
|
1863
|
+
if (wsHit) {
|
|
1864
|
+
return {
|
|
1865
|
+
range: {
|
|
1866
|
+
startLineNumber: position.lineNumber,
|
|
1867
|
+
endLineNumber: position.lineNumber,
|
|
1868
|
+
startColumn: word.startColumn,
|
|
1869
|
+
endColumn: word.endColumn
|
|
1870
|
+
},
|
|
1871
|
+
contents: [
|
|
1872
|
+
{ value: `\`\`\`cpp\n${wsHit.detail}\n\`\`\`` },
|
|
1873
|
+
{ value: `Defined in \`${wsHit.file}:${wsHit.line}\`` }
|
|
1874
|
+
]
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1877
|
+
return null;
|
|
1685
1878
|
}
|
|
1686
1879
|
});
|
|
1880
|
+
|
|
1881
|
+
if (typeof monacoInstance.languages.registerDefinitionProvider === 'function' && monacoInstance.Uri) {
|
|
1882
|
+
monacoInstance.languages.registerDefinitionProvider('cpp', {
|
|
1883
|
+
provideDefinition(model: any, position: any) {
|
|
1884
|
+
const word = model.getWordAtPosition(position);
|
|
1885
|
+
if (!word) return null;
|
|
1886
|
+
const wsSyms = collectWorkspaceCppSymbols(model.getValue?.() || '', model.uri?.path || 'main.cpp');
|
|
1887
|
+
const hit = wsSyms.find((s) => s.name === word.word);
|
|
1888
|
+
if (!hit) return null;
|
|
1889
|
+
const uri = typeof monacoInstance.Uri.file === 'function'
|
|
1890
|
+
? monacoInstance.Uri.file('/workspace/' + hit.file.replace(/^\/+/, ''))
|
|
1891
|
+
: model.uri;
|
|
1892
|
+
return {
|
|
1893
|
+
uri,
|
|
1894
|
+
range: {
|
|
1895
|
+
startLineNumber: hit.line,
|
|
1896
|
+
startColumn: hit.col,
|
|
1897
|
+
endLineNumber: hit.line,
|
|
1898
|
+
endColumn: hit.col + hit.name.length
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1901
|
+
}
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1687
1905
|
return true;
|
|
1688
1906
|
} catch (err) {
|
|
1689
1907
|
if (typeof console !== 'undefined' && console.warn) {
|
|
@@ -1895,20 +2113,61 @@ export function analyzeCppSource(source: string, filename = 'main.cpp', vfs?: an
|
|
|
1895
2113
|
}
|
|
1896
2114
|
}
|
|
1897
2115
|
|
|
1898
|
-
// 5.
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
source
|
|
1911
|
-
|
|
2116
|
+
// 5. Balanced-brace check for missing semicolon after class or struct definitions
|
|
2117
|
+
if (stack.length === 0) {
|
|
2118
|
+
const structHeadRegex = /\b(?:struct|class)\s+([A-Za-z_][A-Za-z0-9_]*)\s*(?::[^{;]*)?\{/g;
|
|
2119
|
+
let structMatch: RegExpExecArray | null;
|
|
2120
|
+
while ((structMatch = structHeadRegex.exec(source)) !== null) {
|
|
2121
|
+
const typeName = structMatch[1];
|
|
2122
|
+
let pos = structMatch.index + structMatch[0].length;
|
|
2123
|
+
let depth = 1;
|
|
2124
|
+
let inStr = false;
|
|
2125
|
+
let inChr = false;
|
|
2126
|
+
let inBlk = false;
|
|
2127
|
+
let inLn = false;
|
|
2128
|
+
while (pos < source.length && depth > 0) {
|
|
2129
|
+
const ch = source[pos];
|
|
2130
|
+
const nx = source[pos + 1] || '';
|
|
2131
|
+
if (inLn) {
|
|
2132
|
+
if (ch === '\n') inLn = false;
|
|
2133
|
+
pos++;
|
|
2134
|
+
continue;
|
|
2135
|
+
}
|
|
2136
|
+
if (inBlk) {
|
|
2137
|
+
if (ch === '*' && nx === '/') { inBlk = false; pos += 2; continue; }
|
|
2138
|
+
pos++;
|
|
2139
|
+
continue;
|
|
2140
|
+
}
|
|
2141
|
+
if (!inStr && !inChr) {
|
|
2142
|
+
if (ch === '/' && nx === '/') { inLn = true; pos += 2; continue; }
|
|
2143
|
+
if (ch === '/' && nx === '*') { inBlk = true; pos += 2; continue; }
|
|
2144
|
+
}
|
|
2145
|
+
if (!inChr && ch === '"' && source[pos - 1] !== '\\') { inStr = !inStr; pos++; continue; }
|
|
2146
|
+
if (!inStr && ch === '\'' && source[pos - 1] !== '\\') { inChr = !inChr; pos++; continue; }
|
|
2147
|
+
if (!inStr && !inChr) {
|
|
2148
|
+
if (ch === '{') depth++;
|
|
2149
|
+
else if (ch === '}') depth--;
|
|
2150
|
+
}
|
|
2151
|
+
pos++;
|
|
2152
|
+
}
|
|
2153
|
+
if (depth === 0) {
|
|
2154
|
+
const afterClose = source.slice(pos).replace(/^(?:\s|\/\/[^\n]*\n|\/\*[\s\S]*?\*\/)+/, '');
|
|
2155
|
+
// Valid: `;` immediately OR variable declarators like `p1, *p2;` before next newline/block
|
|
2156
|
+
const validTerminator = /^;|^[A-Za-z_*&][A-Za-z0-9_,\s*&[\]=()]*;/.test(afterClose);
|
|
2157
|
+
if (afterClose.length > 0 && !validTerminator) {
|
|
2158
|
+
const lineIndex = source.slice(0, pos).split('\n').length;
|
|
2159
|
+
diagnostics.push({
|
|
2160
|
+
id: `cpp-missing-semicolon-${lineIndex}`,
|
|
2161
|
+
file: filename,
|
|
2162
|
+
line: lineIndex,
|
|
2163
|
+
col: 1,
|
|
2164
|
+
severity: 'error',
|
|
2165
|
+
message: `Missing semicolon ';' after '${typeName}' class/struct definition.`,
|
|
2166
|
+
source: 'cpp-linter'
|
|
2167
|
+
});
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
1912
2171
|
}
|
|
1913
2172
|
|
|
1914
2173
|
return diagnostics;
|
|
@@ -1998,10 +2257,17 @@ export function installCppExtension(workbench: any, options: ExtendedCppExtensio
|
|
|
1998
2257
|
workbench.cppCompiler = compilerFn;
|
|
1999
2258
|
workbench.cppOptions = toolchain.options;
|
|
2000
2259
|
|
|
2001
|
-
// Register Monaco language service if
|
|
2260
|
+
// Register Monaco language service immediately and queue hook if Monaco loads asynchronously
|
|
2261
|
+
const getWsFiles = () => (workbench && workbench.files ? workbench.files : {});
|
|
2002
2262
|
if (typeof window !== 'undefined' && (window as any).monaco) {
|
|
2003
|
-
registerMonacoCppLanguageService((window as any).monaco);
|
|
2263
|
+
registerMonacoCppLanguageService((window as any).monaco, getWsFiles);
|
|
2264
|
+
}
|
|
2265
|
+
if (!Array.isArray(workbench._monacoReadyHooks)) {
|
|
2266
|
+
workbench._monacoReadyHooks = [];
|
|
2004
2267
|
}
|
|
2268
|
+
workbench._monacoReadyHooks.push((monaco: any) => {
|
|
2269
|
+
registerMonacoCppLanguageService(monaco, getWsFiles);
|
|
2270
|
+
});
|
|
2005
2271
|
|
|
2006
2272
|
if (!workbench.enabledLanguages || !(workbench.enabledLanguages instanceof Set)) {
|
|
2007
2273
|
workbench.enabledLanguages = new Set(['js', 'cpp']);
|