11<script setup lang="ts">
2- import { ref } from ' vue'
2+ import { computed , ref } from ' vue'
33import type { EditorState } from ' @codemirror/state'
44import { linter , type Diagnostic } from ' @codemirror/lint'
55import { python } from ' @codemirror/lang-python'
66import { Codemirror } from ' vue-codemirror'
77import ToolApi from ' @/api/admin/workspace/tool/tool'
8+ import SystemResourceToolApi from ' @/api/admin/system/resource-management/tool/tool'
9+ import SystemSharedToolApi from ' @/api/admin/system/shared-resources/tool/tool'
810import type { ToolPylintIssue } from ' @/api/types'
11+ import { isSystemResource , isSystemSharedResource } from ' @/utils/resource-context'
912
1013defineOptions ({ name: ' PythonCodeEditor' , inheritAttrs: false })
1114
@@ -16,6 +19,13 @@ const emit = defineEmits<{ submitDialog: [code: string] }>()
1619
1720defineSlots <{ ' header-extra' ? (): unknown }>()
1821
22+ // Python 校验使用当前资源范围的工具接口。
23+ const requestApi = computed (() => {
24+ if (isSystemResource ()) return SystemResourceToolApi
25+ if (isSystemSharedResource ()) return SystemSharedToolApi
26+ return ToolApi
27+ })
28+
1929function getDocumentPosition(state : EditorState , line : number , column : number ) {
2030 const safeLine = Math .max (1 , Math .min (line , state .doc .lines ))
2131 const documentLine = state .doc .line (safeLine )
@@ -35,7 +45,8 @@ const codeLinter = linter(
3545 const lintSource = view .state .doc .toString ()
3646 if (! lintSource .trim ()) return []
3747
38- return ToolApi .postToolPylint (lintSource )
48+ return requestApi .value
49+ .postToolPylint (lintSource )
3950 .then ((issues ) => {
4051 if (lintSource !== view .state .doc .toString ()) return []
4152 return issues .slice (0 , 50 ).map ((issue ) => createDiagnostic (view .state , issue ))
0 commit comments