提交 ca20cec3 编写于 作者: M mxd

优化代码提示

上级 df03cc0c
......@@ -105,6 +105,7 @@ import MagicGroupChoose from '@/components/resources/magic-group-choose.vue'
import { replaceURL, download as downloadFile, requestGroup, goToAnchor, deepClone } from '@/scripts/utils.js'
import contants from '@/scripts/contants.js'
import Key from '@/scripts/hotkey.js'
import JavaClass from "@/scripts/editor/java-class.js"
export default {
name: 'MagicApiList',
......@@ -882,6 +883,15 @@ export default {
}
},
mounted() {
JavaClass.setApiFinder(()=> {
return this.listChildrenData.filter(it => !it.folder).map(it => {
return {
path: replaceURL(it.groupPath + '/' + it.path),
name: replaceURL(it.groupName + '/' + it.name),
method: it.method
}
})
})
this.bus.$on('logout', () => this.tree = [])
this.bus.$on('opened', item => {
this.currentFileItem = item
......
......@@ -836,6 +836,14 @@ export default {
},
mounted() {
JavaClass.setupOnlineFunction(this.doFindFunction);
JavaClass.setFunctionFinder(()=> {
return this.listChildrenData.filter(it => !it.folder).map(it => {
return {
path: replaceURL(it.groupPath + '/' + it.path),
name: replaceURL(it.groupName + '/' + it.name),
}
})
})
this.bus.$on('logout', () => this.tree = []);
this.bus.$on('opened', item => {
this.currentFileItem = item
......
import JavaClass from './java-class.js'
import tokenizer from '../parsing/tokenizer.js'
import {TokenStream, TokenType} from '../parsing/index.js'
import {TokenStream} from '../parsing/index.js'
import {Parser} from '../parsing/parser.js'
import * as monaco from 'monaco-editor'
import RequestParameter from "@/scripts/editor/request-parameter";
......@@ -22,7 +22,40 @@ const completionImport = (suggestions, position, line, importIndex) => {
}))
return;
}
let keyword = line.trim().substring(importIndex + 6).trim().replace(/['|"]/g, '').toLowerCase();
let text = line.trim().substring(importIndex + 6).trim().replace(/['|"]/g, '');
if(text.startsWith('@')){
if(text.indexOf(' ')> -1){
return;
}
let finder = JavaClass.getApiFinder();
(finder && finder() || []).forEach(it => {
let label = '@' + it.method + ':' + it.path
suggestions.push({
sortText: label,
label: label,
kind: monaco.languages.CompletionItemKind.Reference,
filterText: label,
detail: it.name,
insertText: label,
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
})
})
finder = JavaClass.getFunctionFinder();
(finder && finder() || []).forEach(it => {
let label = '@' + it.path
suggestions.push({
sortText: label,
label: label,
kind: monaco.languages.CompletionItemKind.Reference,
filterText: label,
detail: it.name,
insertText: label,
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
})
})
return;
}
let keyword = text.toLowerCase();
let importClass = JavaClass.getImportClass();
if (start !== 0 && keyword && (len = importClass.length) > 0) {
let set = new Set();
......
......@@ -8,6 +8,9 @@ export default {
{token: 'number', foreground: '6897BB'},
{token: 'string', foreground: '6A8759', fontStyle: 'bold'},
{token: 'string.sql', foreground: '6A8759'},
{token: 'tag.sql', foreground: 'E8BF6A'},
{token: 'attribute.name.sql', foreground: 'BABABA'},
{token: 'attribute.value.sql', foreground: '6A8759'},
{token: 'predefined.sql', foreground: 'A9B7C6', fontStyle: 'italic'},
{token: 'predefined.magicscript', foreground: 'A9B7C6', fontStyle: 'italic'},
{token: 'key', foreground: '9876AA'},
......
......@@ -7,6 +7,9 @@ export default {
{token: 'number', foreground: '0000FF'},
{token: 'keyword', foreground: '000080', fontStyle: 'bold'},
{token: 'string.sql', foreground: '008000'},
{token: 'tag.sql', foreground: '0033B3'},
{token: 'attribute.name.sql', foreground: '174AD4'},
{token: 'attribute.value.sql', foreground: '067D17'},
{token: 'predefined', foreground: '000000', fontStyle: 'italic'},
{token: 'operator.sql', foreground: '000080', fontStyle: 'bold'},
{token: 'key', foreground: '660E7A'},
......
......@@ -35,7 +35,7 @@ export const HighLightOptions = {
{token: 'regexp', bracket: '@open', next: '@regexp'}
],
[/[;,.]/, 'delimiter'],
[/"""/, {token: 'string', next: '@string_multi_embedded', nextEmbedded: 'sql'}],
[/"""/, {token: 'string', next: '@string_multi_embedded', nextEmbedded: 'mybatis'}],
[/"([^"\\]|\\.)*$/, 'string.invalid'],
[/'([^'\\]|\\.)*$/, 'string.invalid'],
[/"/, 'string', '@string_double'],
......
......@@ -254,6 +254,16 @@ const getOnlineFunction = (path) => {
return onlineFunctionFinder && onlineFunctionFinder(path);
}
const getDefineModules = () => Object.keys(scriptClass).filter(it => scriptClass[it].module)
let apiFinder;
const setApiFinder = (finder) => {
apiFinder = finder;
}
let functionFinder;
const setFunctionFinder = (finder) => {
functionFinder = finder;
}
const getApiFinder = () => apiFinder
const getFunctionFinder = () => functionFinder
const exportValue = {
findEnums,
findAttributes,
......@@ -273,6 +283,12 @@ const exportValue = {
setupOnlineFunction,
setExtensionAttribute,
getSimpleClass,
getDefineModules
getDefineModules,
setApiFinder,
setFunctionFinder,
getApiFinder,
getFunctionFinder,
}
export default exportValue;
......@@ -4,9 +4,11 @@ import CompletionItemProvider from './completion.js';
import FoldingRangeProvider from './folding.js';
import SignatureHelpProvider from './signature.js';
import HoverProvider from './hover.js';
import {initMybatis} from './mybatis.js'
const Beautifier = require('../beautifier/javascript/beautifier').Beautifier
export const initializeMagicScript = () => {
initMybatis();
const language = 'magicscript';
// 注册语言
monaco.languages.register({id: language});
......@@ -63,6 +65,10 @@ export const initializeMagicScript = () => {
{open: '[', close: ']'},
{open: '(', close: ')'},
{open: '"""', close: '"""', notIn: ['string.multi']},
{open: '<where>', close: '</where>'},
{open: '<if', close: ' test=""></if>'},
{open: '<set>', close: '</set>'},
{open: '<foreach', close: ' collection=""></foreach>'},
{open: '"', close: '"', notIn: ['string']},
{open: '\'', close: '\'', notIn: ['string']},
{open: '/**', close: ' */', notIn: ['string'] }
......
此差异已折叠。
......@@ -110,11 +110,8 @@ export class Parser {
...JavaClass.getAutoImportModule(),
'@import': []
}
// todo 赋值、async、import 未处理
if(nodeLen > 1){
for (let i = 0; i < nodeLen - 1; i++) {
await nodes[i].getJavaType(env)
}
for (let i = 0; i < nodeLen; i++) {
await nodes[i].getJavaType(env)
}
return env
}
......@@ -319,7 +316,6 @@ export class Parser {
} else {
varDefine = new VarDefine(new Span(opening, this.stream.getPrev().getSpan()), token.getText(), null);
}
this.defines.push(varDefine);
return varDefine;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册