Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(syntaxflow):support nativecall/library completion #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@
"yak"
],
"configuration": "./language-configuration.json"
},
{
"id": "syntaxflow",
"aliases": [
"SyntaxFlow",
"syntaxflow"
],
"extensions": [
"sf"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
Expand Down
12 changes: 12 additions & 0 deletions sampleWorkspace/syntaxflow/xxe.sf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
desc (
title: "",
)


a* as $a;

<Hello World!
<Hello World!


<const($a)>
4 changes: 4 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
113 changes: 113 additions & 0 deletions src/syntaxflow.ts
Original file line number Diff line number Diff line change
@@ -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("<include(")) {
return syntaxflow_library_name.map(name => {
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,
)
}