Coder Social home page Coder Social logo

syscrusher / golang.tmbundle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alanquatermain/go-tmbundle

43.0 8.0 9.0 328 KB

A TextMate bundle for the Go programming language

License: Other

Ruby 79.13% Shell 1.69% Go 19.18%
textmate textmate-bundle textmate-grammar go golang gofmt goimports golint gometalinter godef gocode gogetdoc gorename

golang.tmbundle's Introduction

golang.tmbundle

(a TextMate 2 bundle for the go programming language)

Features

  • Syntax highlighting
  • Run, build, test, and install packages
  • Code completion with gocode
  • View documentation with gogetdoc (Requires Go 1.6+)
  • Formatting with gofmt
  • Automatic imports with goimports
  • Linting with golint
  • Multiple linters supported with gometalinter
  • Rename go identifiers with gorename
  • Find symbol information with godef
  • 45 snippets

Installation

TextMate should detect .go files and load this bundle automatically. Syntax highlighting will work, but commands may not.

This bundle relies on amazing open source tooling for some functionality. These utilities can be installed with the following commands:

Command Use
go get -u github.com/nsf/gocode Code completion
go get -u github.com/zmb3/gogetdoc Documentation
go get -u golang.org/x/tools/cmd/goimports Package import resolution/rewriting
go get -u github.com/golang/lint/golint Standard linter
go get -u github.com/alecthomas/gometalinter Combination of multiple linters
go get -u github.com/rogpeppe/godef goto definition
go get -u golang.org/x/tools/cmd/gorename Rename go identifiers

TextMate Variables

TextMate does not inherit the users environment unless it is launched from the command line. You may have to set TM_GOPATH and GOROOT inside of TextMate for all functionality to work. You do not have to set TM_GOPATH if your GOPATH is ~/go and you are running Go >1.8. You do not have to set GOROOT in most circumstances. See here for more information.

You may override the following TextMate variables in the preferences, but most of these should be unnecessary (adjust paths to your own configuration):

Variable Suggested location
TM_GO /usr/local/bin/go
TM_GOPATH /Users/myuser/go
GOROOT /usr/local/opt/go/libexec
TM_GOFMT /Users/myuser/go/bin/gofmt OR TM_GOFMT=/Users/myuser/go/bin/goimports for automatic import resolution on file save
TM_GOCODE /Users/myuser/go/bin/gocode
TM_GOGETDOC /Users/myuser/go/bin/gogetdoc
TM_GOIMPORTS /Users/myuser/go/bin/goimports
TM_GOLINT /Users/myuser/go/bin/golint
TM_GODEF /Users/myuser/go/bin/godef
TM_GOMETALINTER /Users/myuser/go/bin/gometalinter
TM_GORENAME /Users/myuser/go/bin/gorename

Commands

Shortcut Content
Cmd-R Compile and run the current file.
Cmd-Shift-R Compile and test the current package.
Cmd-B Build the current package.
Cmd-Shift-I Install the current package.
Cmd-Shift-D Open either a package listed in imports or a user-supplied package.
Ctrl-H Show the Go HTML documentation for the currently-selected symbol.
Cmd-D Go to the original definition of the currently selected symbol.
Ctrl-Shift-H Reformat the document according to the Go style guidelines, automatically resolve imports.
Ctrl-Shift-L Run 'go lint'
Ctrl-Shift-M Run the default linters supplied by gometalinter
Ctrl-Shift-V Run 'go vet'
Opt-ESC Complete the symbol under the cursor.

Snippets

Simple Statements

Snippet Content
Cmd-i '+iota+'
, A pair ('first, second'), suitable for declaring result variables from a multi-return-value function or a map range loop.
< Send/receive through a channel. Provides tab stops for the value and the channel name.
def A default clause within a switch.
fmt fmt.Println with tab stop for interface
fmt. fmt.Printf with tab stops for string and interface
in An empty interface type (i.e. matches anything).
imp An import statement with optional alternative name.
imps A multiple-import statement.
pkg A package declaration including an optional comment block for packages other than 'main'.
ret A return statement with optional return value.

Initializers and Declarations

Snippet Content
: A short-form variable initializer (i.e. 'name := value').
[] A slice variable type; expands to '[]+type+', so is usable inside other snippets.
ch A channel type.
con A single constant declaration.
cons A multiple constant declaration block.
fun A function type definition statement.
inte An interface definition with a single method.
mk A make statement (used for creating & initializing channels, maps, etc.).
map A map variable type; expands to 'map[+keytype+]+valuetype+'.
ew A new statement (used to create & initialize structure types).
st A struct definition with a single member.
type A type declaration, with name and variable type as tab-stops.
types A block with multiple type declarations.
var Declare a variable with an optional initial value (long form, i.e. 'var x int = 10').
vars A block of long-form variable declarations.

Functions

Snippet Content
de A deferred goroutine call (defines the function inline).
func A plain (global) function declaration, with tab stops for name, parameters, and a single optional result.
funcv A plain (global) function declaration, with tab stops for name, parameters, and multiple results.
go An immediate goroutine call (defines the function inline).
init A template for a module's +init()+ function, with a tab stop at its body.
main A template for a +main()+ function with a tab stop at its body.
meth Declares a function on a particular type, with additional tab stops for receiver name and type and a single optional result.
methv Declares a function on a particular type, with additional tab stops for receiver name and type and multiple results.

Control Statements

Snippet Content
case A case clause, within a switch or select.
for A for loop.
fori A for loop with an index (similar to C for loops).
forr A for loop iterating over a collection's full range.
if An if statement, properly formatted (Go requires the use of {} on ifs, unlike C; this throws me sometimes).
sel A select statement, for looping over channel conditions.
sw A switch statement with an optional expression.

Thanks

This repository is a fork from Jim Dovey's bundle with additional improvements merged from around the community. Changes from the original version (see git log for more details):

  • Substantially improved syntax highlighting (thanks nanoant)
  • Support for goimports and golint (thanks fmccann)
  • Support for godef (thanks taterbase)
  • Users can supply commands via ENV variables (TM_GO_DYNAMIC_GOPATH, TM_GO_DYNAMIC_PKG, TM_GO_DYNAMIC_PKG_PATH). The bundle will consult these commands if defined to dynamically change the gopath or package based on the current directory. (thanks fmccann)
  • all non-run go commands operate on the current directory instead of per file if the package is not defined dynamically. (thanks tg).
  • run and build work on unsaved files (thanks tg)
  • added print, println, printf, and fprintf snippets; improved struct snippet (thanks jish)
  • HiDPI completion icons (thanks nanoant)
  • Bug fixes and improvements (thanks msoap)
  • Improved, expanded documentation coverage (thanks syscrusher)
  • Completion support for GOPATH and current package (thanks syscrusher)
  • bugfixes (thanks everyone!)

Jim Dovey deserves everyone's gratitude for his hard work on this bundle. The following are his original attributions:

Much of the current infrastructure was created by Martin Kühl, who is a significantly more seasoned TextMate bundle developer than I, and to whom I am eternally grateful.

Support for Go 1.0 was provided by Jeremy Whitlock and Michael Sheets, with additional code and fixes from Sylvain Defresne, liuyork, and Alexey Palazhchenko.

Thanks be to lasersox and Infininight over at the #textmate room on IRC for all their help in cleaning up this here bundle, and for helping me to optimize my regex use in the language grammar. Thanks to Martin Kühl for his extensive additions to this project's snippets and commands. Also Infininight's work on updating the bundle to use the TextMate's new Ruby interface and Jeremy & Sylvain's work on supporting Go 1.0 has been invaluable. Their assistance and stewardship while I've been deep in the world of Objective-C is very much appreciated.

Happy coding :)

golang.tmbundle's People

Contributors

alanquatermain avatar aleksi avatar chrisseaton avatar dhowden avatar drnic avatar fmccann avatar guncha avatar infininight avatar jish avatar mkaz avatar mkhl avatar msoap avatar nanoant avatar nicholasklick avatar okcpt avatar puchupala avatar rdwampler avatar robsonpeixoto avatar rsesek avatar schmurfy avatar sdefresne avatar sleetdrop avatar sorbits avatar syscrusher avatar tassolee avatar taterbase avatar tg avatar tomaszj avatar whitlockjc avatar willfaught avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

golang.tmbundle's Issues

Setting TM_GOFMT to goimports binary removes imports with go- prefix

If TM_GOFMT is set to the goimports binary and if you have a file that uses a go- prefixed package such as...

package main

import(
  "github.com/armon/go-radix"
}

func main() {
  _ := radix.New()
}

Saving the file will remove the go-radix import leaving it broken. Running goimports on it manually does not cause this issue.

env: ruby18: No such file or directory

When I format Go code, I get this error:

Failure running “Imports”.

env: ruby18: No such file or directory

Can't the code just specify ruby? Why the dependency on 1.8?

Failure running "run".

Hi there, I've recently started getting this error when I attempt to run a go file in textmate 2.0-beta.6.7 / 2.0-beta.6.8

I've clone this repo in to ~/Library/Application Support/Avian/Bundles/golang.tmbundle and as you can see in the output below it is attempting to run the go code using this plugin. Any thoughts on how to trouble-shoot this ?

Error message:

~/Library/Application Support/Avian/Bundles/golang.tmbundle/Support/gomate.rb:26:in `go': undefined method `length' for nil:NilClass (NoMethodError)
    from Run:4

"edit command" source

#!/usr/bin/env ruby18

require "#{ENV['TM_BUNDLE_SUPPORT']}/gomate"
Go::go "run", :verb => "Running"

Let me know if there's anything else I can do to help.

Does not show completion windows from go-code

OS X 10.11.5
TextMate version 2.0-beta.9
go-code lasted for 2016/05/18
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]

Where I press Opt+Esc, the logs from gocode -debug looks fine.
But the TM2 does not show any windows for any completion.
An error, tool tip "No completions found." showed.

Sorry for my Eng.

Current bundle lacks mandatory keys in property list file

Forgive me because I am still learning about TextMate Bundles. The current version of this bundle does not import properly due to the above mentioned issue.

screen shot 2016-09-13 at 11 03 20 pm

The commit before the latest 2a503ab09fd0c8bbe75bb0090880d9b6b0afd7a8 does work however (and I'm not yet sure why that is).

Empty TM_GOPATH breaks compilation

When TM_GOPATH is not set, the resulting gopath is :$GOPATH. The leading colon seems to make go1.5 interpret this as a relative path and compilations end up with following errors:

go: GOPATH entry is relative; must be absolute path: "". Run 'go help gopath' for usage.

This can be verified by running go build from command line:

$ GOPATH=:/go go build
go: GOPATH entry is relative; must be absolute path: "".
Run 'go help gopath' for usage.

The issue was fixed by me and cherry-picked in cf4a250

The change was then reverted by cherry-pick of 2653890

Anyone else faces similar issue or having problems with fix proposed in cf4a250?

Saving a file removes needed imports

I've noticed in the past day or two that saving a file will appear to goimports-format it, as it removes imports, however those imports are actually needed to build. Not sure what's going on here, I would expect goimports to work the same whether it's hooked into the file-save feature or run manually through the bundle menu or keyboard shortcut.

Grammar: Invalid includes #storage_type|#storage_modifier

Noticed these when monitoring log output from TextMate. There are two places where #storage_type and #storage_modifier are both included but neither of these repository items exist. Since they don't do anything they should be removed but wanted to bring it up to make sure they aren't intended to do something.

Documentation doesn't work for types or non-standard packages

When I highlight Eligible below:

if err := thing.Eligible(c); err != nil {

and press ^H for documentation, this error appears in a temporary popover:

2015/06/11 15:14:44 open /usr/local/Cellar/go/1.4.2/libexec/src/Evidence: no such file or directory

Is this feature only supposed to work for standard library packages? Can I not get documentation for custom packages, or types in packages (even standard ones)?

Doesn't work for me at all

I can't get this bundle to work. My go environment is set up properly, it works fine on the command line (using go version go1.5.2 darwin/amd64 from macports, GOROOT=/opt/local/lib/go, GOPATH=$HOME/Source/Go). I've installed all the tools via "go get" as found on the golang site and also refreshed them according to your README. After fiddling around with my problems I've also done a fresh install of TextMate (2.0-beta.8.5) and reinstalled the Go bundle with the preference pane.
My OS is 10.11.2 with all updates installed.

My Problems are:

  • can't edit any go file. As soon as I save a file or do a goimports (CTRL-SHIFT-H or Menu item) or a gofmt (Menu item), all my changes are lost and the file reverts to the state where I've opened it.
  • can't build or install. When I try to build a program or module, even a simple $GOPATH/src/Hello/main.go with a simple "Hello Word"-Statement, I get a "can't load package: package /Users/xxxx/Source/Go/src/Hello: import "/Users/xxxx/Source/Go/src/Hello": cannot import absolute path".

I've tried to set all the TM_GO-Vars in the README, tried also to set only PATH and GOPATH or TM_GOPATH, and a lot of combinations. I've also double checked that only one "goimports" can be found and all tools work well if called directly on the shell prompt. I'm really stuck here.

The only thing that really works is "run". Is there any debug mode where I could find more information?
BTW, I've none of the TM_GO_DYNAMIC* vars set.

Syntax highlighting is wrong

I think it's pretty obvious if you take a look. I'd be happy to dig into it myself, but don't understand how it works. Can someone point me to a tutorial or give me a crash course?

Preference-Variables not working...

It just keep show me Unable to run “Fmt”.
I have add those variables to the settings. And add those to the system env file then run mate some.go, still not working.

macOS sierra

textmate2

Code Completion Key Bindings

Hi there,

is it possible to change the code completion key bindings to be from the current Opt+Esc to Tab (or double tab) key ?
Is there any way to customise the key bindings?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.