diff --git a/package.json b/package.json index 8ac1354..9afb9fa 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,17 @@ "yak" ], "configuration": "./language-configuration.json" + }, + { + "id": "syntaxflow", + "aliases": [ + "SyntaxFlow", + "syntaxflow" + ], + "extensions": [ + "sf" + ], + "configuration": "./language-configuration.json" } ], "grammars": [ diff --git a/sampleWorkspace/syntaxflow/xxe.sf b/sampleWorkspace/syntaxflow/xxe.sf new file mode 100644 index 0000000..3e2d331 --- /dev/null +++ b/sampleWorkspace/syntaxflow/xxe.sf @@ -0,0 +1,12 @@ +desc ( + title: "", +) + + +a* as $a; + + \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index e68de89..6a9c1f9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -9,6 +9,7 @@ import * as commands from './commands'; import { CompletionSchema, getCompletions } from './completionSchema'; import { registerStatusBar } from './statusbar'; import { findYakBinary } from './utils/path'; +import { registerSyntaxflow } from './syntaxflow'; export function activate(context: vscode.ExtensionContext) { @@ -169,6 +170,9 @@ export function activate(context: vscode.ExtensionContext) { // statusbar registerStatusBar(context); + // syntaxflow + registerSyntaxflow(context); + // commands let commandExecFile = vscode.commands.registerCommand('yak.exec.file', args => { return commands.execFile(context)(args) diff --git a/src/syntaxflow.ts b/src/syntaxflow.ts new file mode 100644 index 0000000..5e1bedf --- /dev/null +++ b/src/syntaxflow.ts @@ -0,0 +1,113 @@ + + +import { log } from 'console'; +import * as vscode from 'vscode'; + +const SyntaxflowSelector = "syntaxflow"; + +const syntaxflow_native_call_name = [ + "getReturns", + "getFormalParams", + "getFunc", + "getCall", + "getCaller", + "searchFunc", + "getObject", + "getMembers", + "getSiblings", + "typeName", + "fullTypeName", + "name", + "string", + "include", + "eval", + "fuzztag", + "show", + "slice", + "regexp", + "strlower", + "strupper", + "var", + "mybatisSink", + "freeMarkerSink", + "opcodes", + "sourceCode", + "scanPrevious", + "scanNext", + "delete", + "forbid", + "self", + "dataflow", + "const", + "versionIn", + "isSanitizeName", +] + + +const syntaxflow_library_name = [ + "java-alibaba-druid-httpclientutil", + "java-apache-commons-httpclient", + "java-apache-http-request-url", + "java-http-fluent-request", + "java-http-sink", + "java-image-io-read-url", + "java-net-url-connect", + "java-spring-rest-template-use", + "command-exec-sink", + "java-spring-param", + "jdbc-prepared-execute-sink", + "jdbc-raw-execute-sink", + "process-builder-sink", + "runtime-exec-sink", + "java-js-sink", + "java-servlet-param", + "write-filename-sink", + "php-filter-function", + "php-param", + "php-os-exec", + "php-file-read", + "php-file-unlink", + "php-file-write", + "php-tp-all-extern-variable-param-source", +] + +const syntaxflow_completion_provider = vscode.languages.registerCompletionItemProvider( + SyntaxflowSelector, + { + provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) { + const linePrefix = document.lineAt(position).text + console.log("lineprefix: ", linePrefix); + + if (linePrefix.startsWith(" { + let item = new vscode.CompletionItem(name); + item.insertText = new vscode.SnippetString(`"${name}"`); + item.documentation = new vscode.MarkdownString(`include library ${name}`); + return item + }) + } + + + // native call + if (linePrefix.startsWith("<")) { + return syntaxflow_native_call_name.map(name => { + let item = new vscode.CompletionItem(name); + item.insertText = new vscode.SnippetString(`${name}` + "(${1:v1})>"); + item.documentation = new vscode.MarkdownString(`native call ${name}`); + return item + }) + } + }, + }, + '<', +) +// function syntaxflow_completion_provider() { + +// } + +// export function +export function registerSyntaxflow(context: vscode.ExtensionContext) { + context.subscriptions.push( + syntaxflow_completion_provider, + ) +} \ No newline at end of file