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

add support for relative path in per-project 'GOPATH' #608

Open
wants to merge 2 commits 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
17 changes: 17 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ This automatically changes `GOPATH` to the value of `$GS_GOPATH` if `$GS_GOPATH`
This allows you to e.g. automatically adapt `GOPATH` to your current project rather than
reverting to your normal `GOPATH`.

Another way is to use relative path:

`my-project.sublime-project`

{
"settings": {
"GoSublime": {
"env": {
"GOPATH": "${project_folder}/.vendor"
}
}
},
"folders": []
}

`${project_folder}` will expand to the path containing your '.sublime-project' file.

Lint/Syntax Check
-----------------

Expand Down
17 changes: 17 additions & 0 deletions gsev.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import gstest
import sublime
import sublime_plugin
import os
import string

DOMAIN = 'GsEV'

Expand Down Expand Up @@ -57,6 +59,20 @@ def do_post_save(view):
finally:
gs.end(tid)

def get_project_folder():
proj_file = sublime.active_window().project_file_name()
if proj_file:
return os.path.dirname(proj_file)
# Use current file's folder when no project file is opened.
return os.path.dirname( sublime.active_window().active_view().file_name() )

def expand_template(s):
mapping = {
"project_folder": get_project_folder()
}
templ = string.Template(s)
return templ.safe_substitute(mapping)

def do_sync_active_view(view):
fn = view.file_name() or ''
gs.set_attr('active_fn', fn)
Expand All @@ -71,6 +87,7 @@ def do_sync_active_view(view):
m = {}
psettings = view.settings().get('GoSublime')
if psettings and gs.is_a(psettings, {}):
psettings['env']['GOPATH'] = expand_template(psettings['env']['GOPATH'])
m = gs.mirror_settings(psettings)
gs.set_attr('last_active_project_settings', gs.dval(m, {}))

Expand Down