Open vscode on at error position on script failure

This commit is contained in:
tong 2021-08-02 21:32:54 +02:00
parent 156f1f433a
commit 4f3c9849c4
2 changed files with 56 additions and 18 deletions

View file

@ -73,7 +73,7 @@ def run_proc(cmd, done: Callable) -> subprocess.Popen:
else:
done()
p = subprocess.Popen(cmd)
p = subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
if use_thread:
threading.Thread(target=wait_for_proc, args=(p,)).start()
@ -481,14 +481,53 @@ def build_done():
if state.proc_build is None:
return
result = state.proc_build.poll()
state.proc_build = None
state.redraw_ui = True
# state.proc_build = None
# state.redraw_ui = True
# if result == 0:
# bpy.data.worlds['Arm'].arm_recompile = False
# build_success()
# else:
# log.error('Build failed, check console')
if result == 0:
state.proc_build = None
state.redraw_ui = True
bpy.data.worlds['Arm'].arm_recompile = False
build_success()
else:
log.error('Build failed, check console')
# log.error('Build failed')
err = state.proc_build.communicate()[1].decode("utf-8").strip()
err = err.split("\n")[0]
log.error(err)
if arm.utils.get_arm_preferences().open_script_error:
try:
parts = err.split(":")
path = parts[0]
linenum = parts[1]
column = parts[2][12:-1].split("-")
arm.utils.open_editor(path,linenum,column[0])
except:
log.debug('Failed to parse error position')
state.proc_build = None
state.redraw_ui = True
# def build_fail(info=None):
# if info != None:
# log.error(info,'')
# if state.proc_build != None:
# err = state.proc_build.communicate()[1].decode("utf-8").strip()
# err = err.split("\n")[0]
# log.error(err)
# if arm.utils.get_arm_preferences().open_script_error:
# try:
# parts = err.split(":")
# path = parts[0]
# linenum = parts[1]
# column = parts[2][12:-1].split("-")
# arm.utils.open_editor(path,linenum,column[0])
# except:
# log.debug('Failed to parse error position')
# state.proc_build = None
# state.redraw_ui = True
def runtime_to_target():
wrd = bpy.data.worlds['Arm']

View file

@ -748,13 +748,14 @@ def export_bone_data(bobject: bpy.types.Object) -> bool:
return bobject.find_armature() and is_bone_animation_enabled(bobject) and get_rp().arm_skin == 'On'
def open_editor(hx_path=None):
def open_editor(hx_path=None,line=None,pos=None):
ide_bin = get_ide_bin()
editor = get_code_editor()
if hx_path is None:
hx_path = arm.utils.get_fp()
if get_code_editor() == 'default':
if editor == 'default':
# Get editor environment variables
# https://unix.stackexchange.com/q/4859
env_v_editor = os.environ.get('VISUAL')
@ -773,33 +774,31 @@ def open_editor(hx_path=None):
if os.path.exists(ide_bin):
args = [ide_bin, arm.utils.get_fp()]
# Sublime Text
if get_code_editor() == 'sublime':
if editor == 'sublime':
project_name = arm.utils.safestr(bpy.data.worlds['Arm'].arm_project_name)
subl_project_path = arm.utils.get_fp() + f'/{project_name}.sublime-project'
if not os.path.exists(subl_project_path):
generate_sublime_project(subl_project_path)
args += ['--project', subl_project_path]
args.append('--add')
args.append(hx_path)
args.append(hx_path)
elif editor == 'code'or ide_bin == 'code' or editor == 'kodestudio':
args.append('--goto')
goto = hx_path
if line != None: goto += ":"+line
if pos != None: goto += ":"+pos
args.append(goto)
else:
args.append(hx_path)
if arm.utils.get_os() == 'mac':
argstr = ""
for arg in args:
if not (arg.startswith('-') or arg.startswith('--')):
argstr += '"' + arg + '"'
argstr += ' '
subprocess.Popen(argstr[:-1], shell=True)
else:
subprocess.Popen(args)
else:
raise FileNotFoundError(f'Code editor executable not found: {ide_bin}. You can change the path in the Armory preferences.')