From 0c0ca0a3a4efeb75d02f42837fef841cf4e6c37f Mon Sep 17 00:00:00 2001 From: ccll Date: Tue, 3 Mar 2015 20:16:40 +0800 Subject: [PATCH] add support for relative path in per-project 'GOPATH' --- USAGE.md | 17 +++++++++++++++++ gsev.py | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/USAGE.md b/USAGE.md index 36db545d..77fab94c 100644 --- a/USAGE.md +++ b/USAGE.md @@ -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 ----------------- diff --git a/gsev.py b/gsev.py index c79301fb..74793f0a 100644 --- a/gsev.py +++ b/gsev.py @@ -2,6 +2,8 @@ import gstest import sublime import sublime_plugin +import os +import string DOMAIN = 'GsEV' @@ -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) @@ -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, {}))