Skip to content

Commit

Permalink
fix: codelens duplication issues #24
Browse files Browse the repository at this point in the history
Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll committed Mar 22, 2024
1 parent 6642f7f commit 6610a57
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/views/editor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script setup lang="ts">
import * as monaco from 'monaco-editor';
import { storeToRefs } from 'pinia';
import { onMounted, ref, watch } from 'vue';
import { onMounted, onUnmounted, ref, watch } from 'vue';
import { useMessage } from 'naive-ui';
import {
buildSearchToken,
Expand Down Expand Up @@ -106,13 +106,15 @@ const refreshActionMarks = (editor: Editor, searchTokens: SearchToken[]) => {
) as unknown as Decoration[];
};
const buildCodeLens = (searchTokens: SearchToken[]) =>
searchTokens.map(({ actionPosition, qdslPosition }, index) => ({
range: actionPosition,
id: `AutoIndent-${index}`,
command: { id: autoIndentCmdId!, title: 'Auto Indent', arguments: [qdslPosition] },
}));
searchTokens
.filter(({ qdslPosition }) => qdslPosition)
.map(({ actionPosition, qdslPosition }, index) => ({
range: actionPosition,
id: `AutoIndent-${index}`,
command: { id: autoIndentCmdId!, title: 'Auto Indent', arguments: [qdslPosition] },
}));
monaco.languages.registerCodeLensProvider('search', {
const codeLensProvider = monaco.languages.registerCodeLensProvider('search', {
provideCodeLenses: () => {
const model = queryEditor?.getModel();
if (!model) {
Expand All @@ -130,10 +132,6 @@ monaco.languages.registerCodeLensProvider('search', {
return { lenses: buildCodeLens(searchTokens), dispose: () => {} };
},
resolveCodeLens: (model, codeLens) => {
return codeLens;
},
});
const executionGutterClass = 'execute-button-decoration';
Expand Down Expand Up @@ -165,7 +163,6 @@ const executeQueryAction = async (
message.error(lang.t('editor.establishedRequired'), {
closable: true,
keepAliveOnHover: true,
duration: 3000,
});
return;
}
Expand All @@ -180,7 +177,6 @@ const executeQueryAction = async (
message.error(`status: ${status}, details: ${details}`, {
closable: true,
keepAliveOnHover: true,
duration: 3000,
});
}
};
Expand Down Expand Up @@ -255,6 +251,10 @@ onMounted(async () => {
setupJsonEditor();
});
onUnmounted(() => {
codeLensProvider.dispose();
});
const { sourceFileAPI } = window;
sourceFileAPI.onSaveShortcut(async () => {
Expand Down

0 comments on commit 6610a57

Please sign in to comment.