Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions website/src/extensions/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import {
IEditorTab,
IExtension,
IMoleculeContext,
TabGroup,
UniqueId
TabGroup
} from '@dtinsight/molecule';
import lips from '@jcubic/lips';

import * as monaco from 'monaco-editor';
import { vsPlusTheme } from 'monaco-sql-languages/esm/main';
Expand Down Expand Up @@ -37,6 +35,8 @@ import TreeVisualizerPanel from '@/components/treeVisualizerPanel';

const problemsService = new ProblemsService();

// eslint-disable-next-line @typescript-eslint/ban-types
const disposed: { dispose: Function; [key: string]: any }[] = [];
export const mainExt: IExtension = {
id: 'mainExt',
name: 'mainExt',
Expand Down Expand Up @@ -267,6 +267,7 @@ export const mainExt: IExtension = {
)
}
]);
molecule.panel.remove('panel.item.output');

molecule.panel.add({
id: 'problem',
Expand Down Expand Up @@ -379,7 +380,7 @@ export const mainExt: IExtension = {
);
});

molecule.editor.onContextMenuClick((item, tabId, groupId) => {
molecule.editor.onContextMenuClick((item) => {
switch (item.id) {
case 'parse': {
updateParseTree(molecule, languageService);
Expand All @@ -391,8 +392,7 @@ export const mainExt: IExtension = {
}
});

molecule.editor.onFocus((item) => {
const groupId = (molecule.editor.getCurrentGroup() || -1) as UniqueId;
molecule.editor.onModelMount((_, groupId) => {
const tab = molecule.editor.getCurrentTab();
if (tab?.id && tab.language) {
molecule.editor.setCurrent(tab?.id, groupId);
Expand All @@ -406,15 +406,17 @@ export const mainExt: IExtension = {
analyzeProblems({ fileData, molecule, tab, languageService });
debounceUpdateParseTree(molecule, languageService);
});
},
dispose() {
disposed.forEach((d) => d.dispose());
}
};

const analyzeProblems = debounce((info: any) => {
const { fileData, molecule, tab, languageService } = info || {};
const { value: sql, language } = fileData || {};

// todo: 一定要 active Tab 才能获取到 language
if (!language) return;
if (!language || !sql) return;

languageService.valid(language.toLocaleLowerCase(), sql).then((res: ParseError[]) => {
const problems = convertMsgToProblemItem(tab, sql, res);
Expand Down Expand Up @@ -489,7 +491,13 @@ const updateParseTree = (molecule: IMoleculeContext, languageService: LanguageSe
const language = activeTab?.language?.toLocaleLowerCase();

if (!parseTreePanel || !language || !activeTab) return;
const sql = activeTab.model?.getValue() || '';
// 为了解决 activeTab?.model 可能是 undefined 进行getValue 会出现报错问题
let sql = '';
try {
sql = activeTab?.model?.getValue() || '';
} catch (e) {
sql = '';
}

languageService.getSerializedParseTree(language, sql).then((tree) => {
molecule.panel.update({
Expand Down
2 changes: 1 addition & 1 deletion website/src/workbench/problems/clients/paneView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const treeLeafSubInfoClassName = getBEMElement(treeLeafClassName, 'subInfo');

function ProblemsPaneView({ problemsService }: { problemsService: any }) {
const localize = useLocale();
const [data, setData] = useState(() => problemsService.get());
const [data, setData] = useState(() => problemsService.get()?.filter(Boolean));

useEffect(() => {
const unsubscribe = problemsService.subscribeData(setData);
Expand Down