Ejemplo n.º 1
0
def PathsToAllGadgetConfigs( vimspector_base, current_file ):
  yield install.GetGadgetConfigFile( vimspector_base )
  for p in sorted( glob.glob(
    os.path.join( install.GetGadgetConfigDir( vimspector_base ),
                  '*.json' ) ) ):
    yield p

  yield utils.PathToConfigFile( '.gadgets.json',
                                os.path.dirname( current_file ) )
Ejemplo n.º 2
0
def WriteAdapters(all_adapters, to_file=None):
    adapter_config = json.dumps({'adapters': all_adapters},
                                indent=2,
                                sort_keys=True)

    if to_file:
        to_file.write(adapter_config)
    else:
        with open(install.GetGadgetConfigFile(options.vimspector_base),
                  'w') as f:
            f.write(adapter_config)
Ejemplo n.º 3
0
def ReadAdapters(read_existing=True):
    all_adapters = {}
    if read_existing:
        try:
            with open(install.GetGadgetConfigFile(options.vimspector_base),
                      'r') as f:
                all_adapters = json.load(f).get('adapters', {})
        except OSError:
            pass

    # Include "built-in" adapter for multi-session mode
    all_adapters.update({
        'multi-session': {
            'port': '${port}',
            'host': '${host}'
        },
    })

    return all_adapters
Ejemplo n.º 4
0
    if not gadget.get('enabled', True):
        if (not args.force_all
                and not getattr(args, 'force_enable_' + gadget['language'])):
            continue
    else:
        if not args.all and not getattr(args, 'enable_' + gadget['language']):
            continue
        if getattr(args, 'disable_' + gadget['language']):
            continue

    InstallGagdet(name, gadget, failed, all_adapters)

for name, gadget in CUSTOM_GADGETS.items():
    InstallGagdet(name, gadget, failed, all_adapters)

adapter_config = json.dumps({'adapters': all_adapters},
                            indent=2,
                            sort_keys=True)

if args.no_gadget_config:
    print("")
    print("Would write the following gadgets: ")
    print(adapter_config)
else:
    with open(install.GetGadgetConfigFile(vimspector_base), 'w') as f:
        f.write(adapter_config)

if failed:
    raise RuntimeError('Failed to install gadgets: {}'.format(
        ','.join(failed)))
Ejemplo n.º 5
0
            ExtractZipTo(file_path,
                         root,
                         format=gadget['download'].get('format', 'zip'))
        elif 'repo' in gadget:
            url = string.Template(gadget['repo']['url']).substitute(v)
            ref = string.Template(gadget['repo']['ref']).substitute(v)

            destination = os.path.join(gadget_dir, 'download', name)
            CloneRepoTo(url, ref, destination)
            root = destination

        if 'do' in gadget:
            gadget['do'](name, root)
        else:
            MakeExtensionSymlink(name, root)

        all_adapters.update(gadget.get('adapters', {}))

        print("Done installing {}".format(name))
    except Exception as e:
        traceback.print_exc()
        failed.append(name)
        print("FAILED installing {}: {}".format(name, e))

with open(install.GetGadgetConfigFile(os.path.dirname(__file__)), 'w') as f:
    json.dump({'adapters': all_adapters}, f, indent=2, sort_keys=True)

if failed:
    raise RuntimeError('Failed to install gadgets: {}'.format(
        ','.join(failed)))
Ejemplo n.º 6
0
    def Start(self, launch_variables={}):
        self._configuration = None
        self._adapter = None

        launch_config_file = utils.PathToConfigFile('.vimspector.json')

        if not launch_config_file:
            utils.UserMessage(
                'Unable to find .vimspector.json. You need to tell '
                'vimspector how to launch your application')
            return

        with open(launch_config_file, 'r') as f:
            database = json.load(f)

        configurations = database.get('configurations')
        adapters = {}

        for gadget_config_file in [
                install.GetGadgetConfigFile(VIMSPECTOR_HOME),
                utils.PathToConfigFile('.gadgets.json')
        ]:
            if gadget_config_file and os.path.exists(gadget_config_file):
                with open(gadget_config_file, 'r') as f:
                    adapters.update(json.load(f).get('adapters') or {})

        adapters.update(database.get('adapters') or {})

        if len(configurations) == 1:
            configuration_name = next(iter(configurations.keys()))
        else:
            configuration_name = utils.SelectFromList(
                'Which launch configuration?',
                sorted(list(configurations.keys())))

        if not configuration_name or configuration_name not in configurations:
            return

        self._workspace_root = os.path.dirname(launch_config_file)

        configuration = configurations[configuration_name]
        adapter = configuration.get('adapter')
        if isinstance(adapter, str):
            adapter = adapters.get(adapter)

        # TODO: Do we want some form of persistence ? e.g. self._staticVariables,
        # set from an api call like SetLaunchParam( 'var', 'value' ), perhaps also a
        # way to load .vimspector.local.json which just sets variables
        self._variables = {
            'dollar': '$',  # HACK. Hote '$$' also works.
            'workspaceRoot': self._workspace_root,
            'gadgetDir': install.GetGadgetDir(VIMSPECTOR_HOME, install.GetOS())
        }
        self._variables.update(
            utils.ParseVariables(adapter.get('variables', {})))
        self._variables.update(
            utils.ParseVariables(configuration.get('variables', {})))
        self._variables.update(launch_variables)

        utils.ExpandReferencesInDict(configuration, self._variables)
        utils.ExpandReferencesInDict(adapter, self._variables)

        if not adapter:
            utils.UserMessage(
                'No adapter configured for {}'.format(configuration_name),
                persist=True)
            return

        self._StartWithConfiguration(configuration, adapter)
Ejemplo n.º 7
0
  def Start( self, launch_variables = {} ):
    self._logger.info( "User requested start debug session with %s",
                       launch_variables )
    self._configuration = None
    self._adapter = None

    launch_config_file = utils.PathToConfigFile( '.vimspector.json' )

    if not launch_config_file:
      utils.UserMessage( 'Unable to find .vimspector.json. You need to tell '
                         'vimspector how to launch your application' )
      return

    with open( launch_config_file, 'r' ) as f:
      database = json.load( f )

    configurations = database.get( 'configurations' )
    adapters = {}

    for gadget_config_file in [ install.GetGadgetConfigFile( VIMSPECTOR_HOME ),
                                utils.PathToConfigFile( '.gadgets.json' ) ]:
      if gadget_config_file and os.path.exists( gadget_config_file ):
        with open( gadget_config_file, 'r' ) as f:
          adapters.update( json.load( f ).get( 'adapters' ) or {} )

    adapters.update( database.get( 'adapters' ) or {} )

    if len( configurations ) == 1:
      configuration_name = next( iter( configurations.keys() ) )
    else:
      configuration_name = utils.SelectFromList(
        'Which launch configuration?',
        sorted( list( configurations.keys() ) ) )

    if not configuration_name or configuration_name not in configurations:
      return

    self._workspace_root = os.path.dirname( launch_config_file )

    configuration = configurations[ configuration_name ]
    adapter = configuration.get( 'adapter' )
    if isinstance( adapter, str ):
      adapter = adapters.get( adapter )

    # TODO: Do we want some form of persistence ? e.g. self._staticVariables,
    # set from an api call like SetLaunchParam( 'var', 'value' ), perhaps also a
    # way to load .vimspector.local.json which just sets variables
    #
    # Additional vars as defined by VSCode:
    #
    # ${workspaceFolder} - the path of the folder opened in VS Code
    # ${workspaceFolderBasename} - the name of the folder opened in VS Code
    #                              without any slashes (/)
    # ${file} - the current opened file
    # ${relativeFile} - the current opened file relative to workspaceFolder
    # ${fileBasename} - the current opened file's basename
    # ${fileBasenameNoExtension} - the current opened file's basename with no
    #                              file extension
    # ${fileDirname} - the current opened file's dirname
    # ${fileExtname} - the current opened file's extension
    # ${cwd} - the task runner's current working directory on startup
    # ${lineNumber} - the current selected line number in the active file
    # ${selectedText} - the current selected text in the active file
    # ${execPath} - the path to the running VS Code executable

    current_file = utils.GetBufferFilepath( vim.current.buffer )

    self._variables = {
      'dollar': '$', # HACK. Hote '$$' also works.
      'workspaceRoot': self._workspace_root,
      'workspaceFolder': self._workspace_root,
      'gadgetDir': install.GetGadgetDir( VIMSPECTOR_HOME, install.GetOS() ),
      'file': current_file,
      'relativeFile': os.path.relpath( current_file, self._workspace_root ),
      'fileBasename': os.path.basename( current_file ),
      'fileBasenameNoExtension':
        os.path.splitext( os.path.basename( current_file ) )[ 0 ],
      'fileDirname': os.path.dirname( current_file ),
      'fileExtname':
        os.path.splitext( os.path.basename( current_file ) )[ 1 ],
      'cwd': os.getcwd(),
    }
    self._variables.update(
      utils.ParseVariables( adapter.get( 'variables', {} ),
                            self._variables ) )
    self._variables.update(
      utils.ParseVariables( configuration.get( 'variables', {} ),
                            self._variables ) )
    self._variables.update( launch_variables )

    utils.ExpandReferencesInDict( configuration, self._variables )
    utils.ExpandReferencesInDict( adapter, self._variables )

    if not adapter:
      utils.UserMessage( 'No adapter configured for {}'.format(
        configuration_name ), persist=True )
      return

    self._StartWithConfiguration( configuration, adapter )