mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 05:55:34 +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));
|
return Array.from(new Set(tokens));
|
||||||
};
|
};
|
||||||
let createDependencyProposals = (range, keyWords, editor, curWord) => {
|
let createDependencyProposals = (range, completions, curWord) => {
|
||||||
let keys = [];
|
let keys = [];
|
||||||
// fix getValue of undefined
|
// fix getValue of undefined
|
||||||
const tokens = getTokens(editor.getModel()?.getValue());
|
const tokens = getTokens(this.codeEditor.getModel()?.getValue());
|
||||||
// 自定义变量、字符串
|
// 自定义变量、字符串
|
||||||
for (const item of tokens) {
|
for (const item of tokens) {
|
||||||
if (item != curWord.word) {
|
if (item != curWord.word) {
|
||||||
@ -267,8 +267,9 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 关键字、函数
|
// 关键字、函数
|
||||||
Object.keys(keyWords).forEach((ItemKind) => {
|
Object.keys(completions).forEach((ItemKind) => {
|
||||||
keyWords[ItemKind].forEach((item) => {
|
if (!Array.isArray(completions[ItemKind])) return;
|
||||||
|
completions[ItemKind].forEach((item) => {
|
||||||
keys.push({
|
keys.push({
|
||||||
label: item,
|
label: item,
|
||||||
kind: monaco.languages.CompletionItemKind[ItemKind],
|
kind: monaco.languages.CompletionItemKind[ItemKind],
|
||||||
@ -288,6 +289,7 @@ export default defineComponent({
|
|||||||
Object.keys(languageCompletions).forEach((language) => {
|
Object.keys(languageCompletions).forEach((language) => {
|
||||||
// 防止自动补全被多次注册
|
// 防止自动补全被多次注册
|
||||||
if (monacoCompletionProviders[language]) return;
|
if (monacoCompletionProviders[language]) return;
|
||||||
|
const completions = languageCompletions[language].default;
|
||||||
monaco.languages.registerCompletionItemProvider(language, {
|
monaco.languages.registerCompletionItemProvider(language, {
|
||||||
provideCompletionItems: function (model, position) {
|
provideCompletionItems: function (model, position) {
|
||||||
var word = model.getWordUntilPosition(position);
|
var word = model.getWordUntilPosition(position);
|
||||||
@ -298,15 +300,22 @@ export default defineComponent({
|
|||||||
endColumn: word.endColumn,
|
endColumn: word.endColumn,
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
suggestions: createDependencyProposals(
|
suggestions: createDependencyProposals(range, completions, word),
|
||||||
range,
|
|
||||||
languageCompletions[language].default,
|
|
||||||
editor,
|
|
||||||
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;
|
monacoCompletionProviders[language] = true;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -355,13 +364,12 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
getHighlighter(language) {
|
getHighlighter(language) {
|
||||||
if (["quickcommand", "javascript", "webjavascript"].includes(language)) {
|
const highLightLanguageDict = {
|
||||||
return "javascript";
|
quickcommand: "javascript",
|
||||||
}
|
webjavascript: "javascript",
|
||||||
if (language === "cmd") {
|
cmd: "bat",
|
||||||
return "bat";
|
};
|
||||||
}
|
return highLightLanguageDict[language] || language;
|
||||||
return language;
|
|
||||||
},
|
},
|
||||||
setCursorPosition(position) {
|
setCursorPosition(position) {
|
||||||
if (!position.lineNumber || !position.column) return;
|
if (!position.lineNumber || !position.column) return;
|
||||||
|
@ -1,8 +1,37 @@
|
|||||||
var Text = ["AppleScript", "false", "linefeed", "return", "pi", "quote", "result", "space", "tab", "true", ];
|
const 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"];
|
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", ];
|
||||||
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", ];
|
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", ];
|
||||||
export default {
|
const Operator = [ "=", "≠", "≤", "≥", "&", "+", "-", "*", "/", "div", "mod", "^", "contains", "equals", "is", "is not", "isnt", "less than", "greater than", "and", "or", "not", ];
|
||||||
Keyword,
|
const Symbol = /[=><!~?:&|+\-*\/\^%]+/;
|
||||||
Function,
|
const Tokenizer = {
|
||||||
Text,
|
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