From ed994d7d56c0534ae5d499dded9d52ff78caf0da Mon Sep 17 00:00:00 2001 From: Mach Date: Sun, 18 Oct 2015 13:43:50 +0800 Subject: [PATCH 1/5] use racer for completion --- Commands/Complete.tmCommand | 86 +++++++++++++++++++++++++++++++++++++ info.plist | 4 +- 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 Commands/Complete.tmCommand diff --git a/Commands/Complete.tmCommand b/Commands/Complete.tmCommand new file mode 100644 index 0000000..4b7f5e3 --- /dev/null +++ b/Commands/Complete.tmCommand @@ -0,0 +1,86 @@ + + + + + beforeRunningCommand + saveActiveFile + command + #!/usr/bin/env ruby18 +require ENV['TM_SUPPORT_PATH'] + '/lib/ui.rb' +require ENV['TM_SUPPORT_PATH'] + "/lib/escape.rb" +require ENV['TM_SUPPORT_PATH'] + "/lib/tm/require_cmd.rb" +require ENV['TM_SUPPORT_PATH'] + "/lib/tm/htmloutput.rb" +require ENV['TM_SUPPORT_PATH'] + "/lib/web_preview" + +# current document +document = [] +File.open(ENV['TM_FILEPATH'], "r+") do |file| + document = file.readlines +end + +# byte offset of cursor position from the beginning of file +cursor = document[ 0, ENV['TM_LINE_NUMBER'].to_i - 1].join().length + ENV['TM_LINE_INDEX'].to_i +line = document[ENV['TM_LINE_NUMBER'].to_i - 1] +word = line.split(' ').last +output = `"$TM_RACER" complete #{word}` + +def make_completion_hash(line) + comp = line.split(",") + match = comp[0].split(" ").last + image = comp[4] + display = comp[5] + return { 'match' => match, 'display' => display, 'insert' => '' } +end + +hashes = output.split("\n").collect{ |line| make_completion_hash(line) } +options = { :extra_chars => "_", :case_insensitive => false } + +# quit if no completions found +TextMate.exit_show_tool_tip("No completions found.") if hashes.length == 0 + +if hashes.length == 1 + word = ENV['TM_CURRENT_WORD'] || "" + snippet = hashes[0]["match"].gsub(/^#{Regexp.escape(word)}/, "") + hashes[0]["insert"] + TextMate.exit_insert_snippet( snippet ) +else + TextMate::UI.complete( hashes , options ) +end + + + fallbackInput + word + hideFromUser + true + input + none + inputFormat + text + keyEquivalent + ~ + name + Complete + outputCaret + afterOutput + outputFormat + text + outputLocation + atCaret + requiredCommands + + + command + racer + moreInfoURL + https://github.com/phildawes/racer + variable + TM_RACER + + + scope + source.rust + uuid + FE908865-7729-4926-9FAC-2D54895BEA48 + version + 2 + + diff --git a/info.plist b/info.plist index c4eeddc..560282e 100644 --- a/info.plist +++ b/info.plist @@ -3,9 +3,9 @@ contactEmailRot13 - pneby.avpubyf@tznvy.pbz + onpx2znpu@tznvy.pbz contactName - Carol (Nichols || Goulding) + Mach description A general-purpose, multi-paradigm, compiled programming language developed by Mozilla Research. mainMenu From 96bbb7b7693ac2388ffb891a2971110d7d0a94c0 Mon Sep 17 00:00:00 2001 From: Mach Date: Sun, 18 Oct 2015 16:43:27 +0800 Subject: [PATCH 2/5] complete both syntax and definition --- Commands/Complete.tmCommand | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Commands/Complete.tmCommand b/Commands/Complete.tmCommand index 4b7f5e3..91fbe33 100644 --- a/Commands/Complete.tmCommand +++ b/Commands/Complete.tmCommand @@ -22,7 +22,12 @@ end cursor = document[ 0, ENV['TM_LINE_NUMBER'].to_i - 1].join().length + ENV['TM_LINE_INDEX'].to_i line = document[ENV['TM_LINE_NUMBER'].to_i - 1] word = line.split(' ').last -output = `"$TM_RACER" complete #{word}` +line_number = ENV['TM_LINE_NUMBER'] +line_index = ENV['TM_LINE_INDEX'] +file_path = ENV['TM_FILEPATH'] +output_syntax = `"$TM_RACER" complete #{line_number} #{line_index} #{file_path}` +output_def = `"$TM_RACER" complete #{word}` +output = output_syntax + "\r" + output_def def make_completion_hash(line) comp = line.split(",") @@ -32,7 +37,7 @@ def make_completion_hash(line) return { 'match' => match, 'display' => display, 'insert' => '' } end -hashes = output.split("\n").collect{ |line| make_completion_hash(line) } +hashes = output.split("\n").select{ |line| line.start_with? "MATCH" }.collect{ |line| make_completion_hash(line) } options = { :extra_chars => "_", :case_insensitive => false } # quit if no completions found From 0fc8fc09bd36801489d8329616747a55b2b404ca Mon Sep 17 00:00:00 2001 From: Mach Date: Sun, 18 Oct 2015 16:53:01 +0800 Subject: [PATCH 3/5] remove duplications in completion --- Commands/Complete.tmCommand | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Commands/Complete.tmCommand b/Commands/Complete.tmCommand index 91fbe33..dc822bb 100644 --- a/Commands/Complete.tmCommand +++ b/Commands/Complete.tmCommand @@ -19,15 +19,14 @@ File.open(ENV['TM_FILEPATH'], "r+") do |file| end # byte offset of cursor position from the beginning of file -cursor = document[ 0, ENV['TM_LINE_NUMBER'].to_i - 1].join().length + ENV['TM_LINE_INDEX'].to_i -line = document[ENV['TM_LINE_NUMBER'].to_i - 1] -word = line.split(' ').last +# cursor = document[ 0, ENV['TM_LINE_NUMBER'].to_i - 1].join().length + ENV['TM_LINE_INDEX'].to_i +# line = document[ENV['TM_LINE_NUMBER'].to_i - 1] +# word = line.split(' ').last + line_number = ENV['TM_LINE_NUMBER'] line_index = ENV['TM_LINE_INDEX'] file_path = ENV['TM_FILEPATH'] -output_syntax = `"$TM_RACER" complete #{line_number} #{line_index} #{file_path}` -output_def = `"$TM_RACER" complete #{word}` -output = output_syntax + "\r" + output_def +output = `"$TM_RACER" complete #{line_number} #{line_index} #{file_path}` def make_completion_hash(line) comp = line.split(",") From 4f69e68d24479ca8259811c6691cfe4cb13105d9 Mon Sep 17 00:00:00 2001 From: Mach Date: Sun, 18 Oct 2015 21:22:44 +0800 Subject: [PATCH 4/5] improve display text for completion --- Commands/Complete.tmCommand | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Commands/Complete.tmCommand b/Commands/Complete.tmCommand index dc822bb..971af67 100644 --- a/Commands/Complete.tmCommand +++ b/Commands/Complete.tmCommand @@ -33,7 +33,8 @@ def make_completion_hash(line) match = comp[0].split(" ").last image = comp[4] display = comp[5] - return { 'match' => match, 'display' => display, 'insert' => '' } + out = "%s\t%s" % [match.ljust(40), display] + return { 'match' => match, 'display' => out, 'insert' => '', 'image' => '' } end hashes = output.split("\n").select{ |line| line.start_with? "MATCH" }.collect{ |line| make_completion_hash(line) } From 02a96be0428fa876e1b5e36b7a70b35632f2e2af Mon Sep 17 00:00:00 2001 From: Mach Date: Sun, 18 Oct 2015 22:31:31 +0800 Subject: [PATCH 5/5] restore author info --- info.plist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/info.plist b/info.plist index 560282e..c4eeddc 100644 --- a/info.plist +++ b/info.plist @@ -3,9 +3,9 @@ contactEmailRot13 - onpx2znpu@tznvy.pbz + pneby.avpubyf@tznvy.pbz contactName - Mach + Carol (Nichols || Goulding) description A general-purpose, multi-paradigm, compiled programming language developed by Mozilla Research. mainMenu