aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth/js.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/geth/js.go')
-rw-r--r--cmd/geth/js.go74
1 files changed, 8 insertions, 66 deletions
diff --git a/cmd/geth/js.go b/cmd/geth/js.go
index 3d0251f08..e7e28b24b 100644
--- a/cmd/geth/js.go
+++ b/cmd/geth/js.go
@@ -80,73 +80,25 @@ type jsre struct {
prompter
}
-var (
- loadedModulesMethods map[string][]string
- autoCompleteStatement = "function _autocomplete(obj) {var results = []; for (var e in obj) { results.push(e); }; return results; }; _autocomplete(%s)"
-)
-
-func keywordCompleter(jsre *jsre, line string) []string {
- var results []string
- parts := strings.Split(line, ".")
- objRef := "this"
- prefix := line
- if len(parts) > 1 {
- objRef = strings.Join(parts[0:len(parts) - 1], ".")
- prefix = parts[len(parts) - 1]
- }
-
- result, _ := jsre.re.Run(fmt.Sprintf(autoCompleteStatement, objRef))
- raw, _ := result.Export()
- if keys, ok := raw.([]interface{}); ok {
- for _, k := range keys {
- if strings.HasPrefix(fmt.Sprintf("%s", k), prefix) {
- if objRef == "this" {
- results = append(results, fmt.Sprintf("%s", k))
- } else {
- results = append(results, fmt.Sprintf("%s.%s", strings.Join(parts[:len(parts) - 1], "."), k))
- }
- }
- }
- }
-
- // e.g. web3<tab><tab> append dot since its an object
- isObj, _ := jsre.re.Run(fmt.Sprintf("typeof(%s) === 'object'", line))
- if isObject, _ := isObj.ToBoolean(); isObject {
- results = append(results, line + ".")
- }
-
- sort.Strings(results)
- return results
-}
-
-func apiWordCompleterWithContext(jsre *jsre) liner.WordCompleter {
- completer := func(line string, pos int) (head string, completions []string, tail string) {
+func makeCompleter(re *jsre) liner.WordCompleter {
+ return func(line string, pos int) (head string, completions []string, tail string) {
if len(line) == 0 || pos == 0 {
return "", nil, ""
}
-
// chuck data to relevant part for autocompletion, e.g. in case of nested lines eth.getBalance(eth.coinb<tab><tab>
i := 0
for i = pos - 1; i > 0; i-- {
if line[i] == '.' || (line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z') {
continue
}
- if i >= 3 && line[i] == '3' && line[i - 3] == 'w' && line[i - 2] == 'e' && line[i - 1] == 'b' {
+ if i >= 3 && line[i] == '3' && line[i-3] == 'w' && line[i-2] == 'e' && line[i-1] == 'b' {
continue
}
i += 1
break
}
-
- begin := line[:i]
- keyword := line[i:pos]
- end := line[pos:]
-
- completionWords := keywordCompleter(jsre, keyword)
- return begin, completionWords, end
+ return line[:i], re.re.CompleteKeywords(line[i:pos]), line[pos:]
}
-
- return completer
}
func newLightweightJSRE(docRoot string, client rpc.Client, datadir string, interactive bool) *jsre {
@@ -165,9 +117,9 @@ func newLightweightJSRE(docRoot string, client rpc.Client, datadir string, inter
lr := liner.NewLiner()
js.withHistory(datadir, func(hist *os.File) { lr.ReadHistory(hist) })
lr.SetCtrlCAborts(true)
- js.loadAutoCompletion()
- lr.SetWordCompleter(apiWordCompleterWithContext(js))
+ lr.SetWordCompleter(makeCompleter(js))
lr.SetTabCompletionStyle(liner.TabPrints)
+ lr.SetMultiLineMode(true)
js.prompter = lr
js.atexit = func() {
js.withHistory(datadir, func(hist *os.File) { hist.Truncate(0); lr.WriteHistory(hist) })
@@ -196,8 +148,7 @@ func newJSRE(stack *node.Node, docRoot, corsDomain string, client rpc.Client, in
lr := liner.NewLiner()
js.withHistory(stack.DataDir(), func(hist *os.File) { lr.ReadHistory(hist) })
lr.SetCtrlCAborts(true)
- js.loadAutoCompletion()
- lr.SetWordCompleter(apiWordCompleterWithContext(js))
+ lr.SetWordCompleter(makeCompleter(js))
lr.SetTabCompletionStyle(liner.TabPrints)
js.prompter = lr
js.atexit = func() {
@@ -209,15 +160,6 @@ func newJSRE(stack *node.Node, docRoot, corsDomain string, client rpc.Client, in
return js
}
-func (self *jsre) loadAutoCompletion() {
- if modules, err := self.supportedApis(); err == nil {
- loadedModulesMethods = make(map[string][]string)
- for module, _ := range modules {
- loadedModulesMethods[module] = rpc.AutoCompletion[module]
- }
- }
-}
-
func (self *jsre) batch(statement string) {
err := self.re.EvalAndPrettyPrint(statement)
@@ -280,7 +222,7 @@ func (js *jsre) apiBindings() error {
utils.Fatalf("Error loading bignumber.js: %v", err)
}
- err = js.re.Compile("ethereum.js", re.Web3_JS)
+ err = js.re.Compile("web3.js", re.Web3_JS)
if err != nil {
utils.Fatalf("Error loading web3.js: %v", err)
}