mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-07 21:46:12 +08:00
修复非JS代码无补全BUG,添加applescript语法高亮
This commit is contained in:
parent
09b201907d
commit
a7b4418945
@ -250,10 +250,10 @@ export default defineComponent({
|
||||
}
|
||||
return Array.from(new Set(tokens));
|
||||
};
|
||||
let createDependencyProposals = (range, keyWords, editor, curWord) => {
|
||||
let createDependencyProposals = (range, completions, curWord) => {
|
||||
let keys = [];
|
||||
// fix getValue of undefined
|
||||
const tokens = getTokens(editor.getModel()?.getValue());
|
||||
const tokens = getTokens(this.codeEditor.getModel()?.getValue());
|
||||
// 自定义变量、字符串
|
||||
for (const item of tokens) {
|
||||
if (item != curWord.word) {
|
||||
@ -267,8 +267,9 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
// 关键字、函数
|
||||
Object.keys(keyWords).forEach((ItemKind) => {
|
||||
keyWords[ItemKind].forEach((item) => {
|
||||
Object.keys(completions).forEach((ItemKind) => {
|
||||
if (!Array.isArray(completions[ItemKind])) return;
|
||||
completions[ItemKind].forEach((item) => {
|
||||
keys.push({
|
||||
label: item,
|
||||
kind: monaco.languages.CompletionItemKind[ItemKind],
|
||||
@ -288,6 +289,7 @@ export default defineComponent({
|
||||
Object.keys(languageCompletions).forEach((language) => {
|
||||
// 防止自动补全被多次注册
|
||||
if (monacoCompletionProviders[language]) return;
|
||||
const completions = languageCompletions[language].default;
|
||||
monaco.languages.registerCompletionItemProvider(language, {
|
||||
provideCompletionItems: function (model, position) {
|
||||
var word = model.getWordUntilPosition(position);
|
||||
@ -298,15 +300,22 @@ export default defineComponent({
|
||||
endColumn: word.endColumn,
|
||||
};
|
||||
return {
|
||||
suggestions: createDependencyProposals(
|
||||
range,
|
||||
languageCompletions[language].default,
|
||||
editor,
|
||||
word
|
||||
),
|
||||
suggestions: createDependencyProposals(range, completions, word),
|
||||
};
|
||||
},
|
||||
});
|
||||
if (language === "applescript") {
|
||||
const { Keyword, Tokenizer, Operator, Symbol } = completions;
|
||||
// applescript 需要再添加语法高亮定义
|
||||
monaco.languages.setMonarchTokensProvider("applescript", {
|
||||
defaultToken: "",
|
||||
tokenPostfix: ".applescript",
|
||||
keywords: Keyword,
|
||||
operators: Operator,
|
||||
symbols: Symbol,
|
||||
tokenizer: Tokenizer,
|
||||
});
|
||||
}
|
||||
monacoCompletionProviders[language] = true;
|
||||
});
|
||||
},
|
||||
@ -355,13 +364,12 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
getHighlighter(language) {
|
||||
if (["quickcommand", "javascript", "webjavascript"].includes(language)) {
|
||||
return "javascript";
|
||||
}
|
||||
if (language === "cmd") {
|
||||
return "bat";
|
||||
}
|
||||
return language;
|
||||
const highLightLanguageDict = {
|
||||
quickcommand: "javascript",
|
||||
webjavascript: "javascript",
|
||||
cmd: "bat",
|
||||
};
|
||||
return highLightLanguageDict[language] || language;
|
||||
},
|
||||
setCursorPosition(position) {
|
||||
if (!position.lineNumber || !position.column) return;
|
||||
|
@ -1,8 +1,37 @@
|
||||
var Text = ["AppleScript", "false", "linefeed", "return", "pi", "quote", "result", "space", "tab", "true", ];
|
||||
var Keyword = ["about", "above", "after", "against", "and", "around", "as", "at", "back", "before", "beginning", "behind", "below", "beneath", "beside", "between", "but", "by", "considering", "contain", "contains", "continue", "copy", "div", "does", "eighth", "else", "end", "equal", "equals", "error", "every", "exit", "fifth", "first", "for", "fourth", "from", "front", "get", "given", "global", "if", "ignoring", "in", "into", "is", "it", "its", "last", "local", "me", "middle", "mod", "my", "ninth", "not", "of", "on", "onto", "or", "over", "prop", "property", "put", "ref", "reference", "repeat", "returning", "script", "second", "set", "seventh", "since", "sixth", "some", "tell", "tenth", "that", "the", "then", "third", "through", "thru", "timeout", "times", "to", "transaction", "try", "until", "where", "while", "whose", "with", "without", "alias", "application", "boolean", "class", "constant", "date", "file", "integer", "list", "number", "real", "record", "string", "text", "character", "characters", "contents", "day", "frontmost", "id", "item", "length", "month", "name", "paragraph", "paragraphs", "rest", "reverse", "running", "time", "version", "weekday", "word", "words", "year"];
|
||||
var Function = ["activate", "beep", "count", "delay", "launch", "log", "offset", "read", "round", "run", "say", "summarize", "write", "clipboard info", "the clipboard", "info for", "list disks", "list folder", "mount volume", "path to", "close for access", "open for access", "get eof", "set eof", "current date", "do shell script", "get volume settings", "random number", "set volume", "system attribute", "system info", "time to GMT", "load script", "run script", "store script", "scripting components", "ASCII character", "ASCII number", "localized string", "folder", "from list", "remote application", "URL", "display alert", "display dialog", ];
|
||||
export default {
|
||||
Keyword,
|
||||
Function,
|
||||
Text,
|
||||
const Text = [ "AppleScript", "false", "linefeed", "return", "pi", "quote", "result", "space", "tab", "true", ];
|
||||
const Keyword = [ "about", "above", "after", "against", "and", "around", "as", "at", "back", "before", "beginning", "behind", "below", "beneath", "beside", "between", "but", "by", "considering", "contain", "contains", "continue", "copy", "div", "does", "eighth", "else", "end", "equal", "equals", "error", "every", "exit", "fifth", "first", "for", "fourth", "from", "front", "get", "given", "global", "if", "ignoring", "in", "into", "is", "it", "its", "last", "local", "me", "middle", "mod", "my", "ninth", "not", "of", "on", "onto", "or", "over", "prop", "property", "put", "ref", "reference", "repeat", "returning", "script", "second", "set", "seventh", "since", "sixth", "some", "tell", "tenth", "that", "the", "then", "third", "through", "thru", "timeout", "times", "to", "transaction", "try", "until", "where", "while", "whose", "with", "without", "alias", "application", "boolean", "class", "constant", "date", "file", "integer", "list", "number", "real", "record", "string", "text", "character", "characters", "contents", "day", "frontmost", "id", "item", "length", "month", "name", "paragraph", "paragraphs", "rest", "reverse", "running", "time", "version", "weekday", "word", "words", "year", ];
|
||||
const Function = [ "activate", "beep", "count", "delay", "launch", "log", "offset", "read", "round", "run", "say", "summarize", "write", "clipboard info", "the clipboard", "info for", "list disks", "list folder", "mount volume", "path to", "close for access", "open for access", "get eof", "set eof", "current date", "do shell script", "get volume settings", "random number", "set volume", "system attribute", "system info", "time to GMT", "load script", "run script", "store script", "scripting components", "ASCII character", "ASCII number", "localized string", "folder", "from list", "remote application", "URL", "display alert", "display dialog", ];
|
||||
const Operator = [ "=", "≠", "≤", "≥", "&", "+", "-", "*", "/", "div", "mod", "^", "contains", "equals", "is", "is not", "isnt", "less than", "greater than", "and", "or", "not", ];
|
||||
const Symbol = /[=><!~?:&|+\-*\/\^%]+/;
|
||||
const Tokenizer = {
|
||||
root: [
|
||||
[
|
||||
/[a-zA-Z_]\w*/,
|
||||
{
|
||||
cases: {
|
||||
"@keywords": "keyword",
|
||||
"@operators": "operator",
|
||||
"@default": "identifier",
|
||||
},
|
||||
},
|
||||
],
|
||||
[/--.*$/, "comment"],
|
||||
[/"/, { token: "string.quote", next: "@string" }],
|
||||
[/\d+/, "number"],
|
||||
[/@symbols/, "operator"],
|
||||
],
|
||||
|
||||
string: [
|
||||
[/[^\"]+/, "string"],
|
||||
[/\"/, { token: "string.quote", next: "@pop" }],
|
||||
],
|
||||
};
|
||||
|
||||
export default {
|
||||
Keyword,
|
||||
Function,
|
||||
Text,
|
||||
Operator,
|
||||
Symbol,
|
||||
Tokenizer,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user