Пример #1
0
  async reset () {
    this.deserializers.clear()
    this.registerDefaultDeserializers()

    this.config.clear()
    this.config.setSchema(null, {type: 'object', properties: _.clone(ConfigSchema)})

    this.keymaps.clear()
    this.keymaps.loadBundledKeymaps()

    this.commands.clear()
    this.registerDefaultCommands()

    this.styles.restoreSnapshot(this.initialStyleElements)

    this.menu.clear()

    this.clipboard.reset()

    this.notifications.clear()

    this.contextMenu.clear()

    await this.packages.reset()
    this.workspace.reset(this.packages)
    this.registerDefaultOpeners()
    this.project.reset(this.packages)
    this.workspace.subscribeToEvents()
    this.grammars.clear()
    this.textEditors.clear()
    this.views.clear()
    this.pathsWithWaitSessions.clear()
  }
Пример #2
0
        }).then((data) => {

          if (!data) {

            return resolve([]);
          }

          if (!data.completions.length) {

            return resolve([]);
          }

          this.suggestionsArr = [];

          let scopesPath = scopeDescriptor.getScopesArray();
          let isInFunDef = scopesPath.indexOf('meta.function.js') > -1;

          for (const obj of data.completions) {

            const completion = formatTypeCompletion(obj, data.isProperty, data.isObjectKey, isInFunDef);

            this.suggestion = {

              text: completion.name,
              replacementPrefix: prefix,
              className: null,
              type: completion._typeSelf,
              leftLabel: completion.leftLabel,
              snippet: completion._snippet,
              displayText: completion._displayText,
              description: completion.doc || null,
              descriptionMoreURL: completion.url || null
            };

            if (packageConfig.options.useSnippetsAndFunction && completion._hasParams) {

              this.suggestionClone = clone(this.suggestion);
              this.suggestionClone.type = 'snippet';

              if (completion._hasParams) {

                this.suggestion.snippet = `${completion.name}($\{0:\})`;

              } else {

                this.suggestion.snippet = `${completion.name}()`;
              }

              this.suggestionsArr.push(this.suggestion);
              this.suggestionsArr.push(this.suggestionClone);

            } else {

              this.suggestionsArr.push(this.suggestion);
            }
          }

          resolve(this.suggestionsArr);

        }).catch((err) => {
          }).then(function (data) {

            if (!data) {

              return resolve([]);
            }

            if (!data.completions.length) {

              return resolve([]);
            }

            _this.suggestionsArr = [];

            var scopesPath = scopeDescriptor.getScopesArray();
            var isInFunDef = scopesPath.indexOf('meta.function.js') > -1;

            for (var obj of data.completions) {

              obj = _this.manager.helper.formatTypeCompletion(obj, isInFunDef);

              _this.suggestion = {

                text: obj.name,
                replacementPrefix: prefix,
                className: null,
                type: obj._typeSelf,
                leftLabel: obj.leftLabel,
                snippet: obj._snippet,
                displayText: obj._displayText,
                description: obj.doc || null,
                descriptionMoreURL: obj.url || null
              };

              if (_this.manager.packageConfig.options.useSnippetsAndFunction && obj._hasParams) {

                _this.suggestionClone = _.clone(_this.suggestion);
                _this.suggestionClone.type = 'snippet';

                if (obj._hasParams) {

                  _this.suggestion.snippet = obj.name + '(${0:})';
                } else {

                  _this.suggestion.snippet = obj.name + '()';
                }

                _this.suggestionsArr.push(_this.suggestion);
                _this.suggestionsArr.push(_this.suggestionClone);
              } else {

                _this.suggestionsArr.push(_this.suggestion);
              }
            }

            resolve(_this.suggestionsArr);
          });
Пример #4
0
        }).then((data) => {

          if (!data) {

            return resolve([]);
          }

          if (!data.completions.length) {

            return resolve([]);
          }

          this.suggestionsArr = [];

          for (let obj of data.completions) {

            obj = this.manager.helper.formatTypeCompletion(obj);

            this.suggestion = {

              text: obj.name,
              replacementPrefix: prefix,
              className: null,
              type: obj._typeSelf,
              leftLabel: obj.leftLabel,
              snippet: obj._snippet,
              displayText: obj._displayText,
              description: obj.doc || null,
              descriptionMoreURL: obj.url || null
            };

            if (this.manager.packageConfig.options.useSnippetsAndFunction && obj._hasParams) {

              this.suggestionClone = _.clone(this.suggestion);
              this.suggestionClone.type = 'snippet';

              if (obj._hasParams) {

                this.suggestion.snippet = `${obj.name}($\{0:\})`;

              } else {

                this.suggestion.snippet = `${obj.name}()`;
              }

              this.suggestionsArr.push(this.suggestion);
              this.suggestionsArr.push(this.suggestionClone);

            } else {

              this.suggestionsArr.push(this.suggestion);
            }
          }

          resolve(this.suggestionsArr);
        });
Пример #5
0
  constructor (options) {
    super()
    this.quitting = false
    this.getAllWindows = this.getAllWindows.bind(this)
    this.getLastFocusedWindow = this.getLastFocusedWindow.bind(this)
    this.resourcePath = options.resourcePath
    this.devResourcePath = options.devResourcePath
    this.version = options.version
    this.devMode = options.devMode
    this.safeMode = options.safeMode
    this.socketPath = options.socketPath
    this.logFile = options.logFile
    this.userDataDir = options.userDataDir
    this._killProcess = options.killProcess || process.kill.bind(process)
    if (options.test || options.benchmark || options.benchmarkTest) this.socketPath = null

    this.waitSessionsByWindow = new Map()
    this.windowStack = new WindowStack()

    this.initializeAtomHome(process.env.ATOM_HOME)

    const configFilePath = fs.existsSync(path.join(process.env.ATOM_HOME, 'config.json'))
      ? path.join(process.env.ATOM_HOME, 'config.json')
      : path.join(process.env.ATOM_HOME, 'config.cson')

    this.configFile = ConfigFile.at(configFilePath)
    this.config = new Config({
      saveCallback: settings => {
        if (!this.quitting) {
          return this.configFile.update(settings)
        }
      }
    })
    this.config.setSchema(null, {type: 'object', properties: _.clone(ConfigSchema)})

    this.fileRecoveryService = new FileRecoveryService(path.join(process.env.ATOM_HOME, 'recovery'))
    this.storageFolder = new StorageFolder(process.env.ATOM_HOME)
    this.autoUpdateManager = new AutoUpdateManager(
      this.version,
      options.test || options.benchmark || options.benchmarkTest,
      this.config
    )

    this.disposable = new CompositeDisposable()
    this.handleEvents()
  }
 sanitizeSuggestionsFromConfig (suggestions, type) {
   if ((suggestions != null) && Array.isArray(suggestions)) {
     const sanitizedSuggestions = []
     for (let i = 0; i < suggestions.length; i++) {
       let suggestion = suggestions[i]
       if (typeof suggestion === 'string') {
         sanitizedSuggestions.push({text: suggestion, type})
       } else if (typeof suggestions[0] === 'object' && ((suggestion.text != null) || (suggestion.snippet != null))) {
         suggestion = _.clone(suggestion)
         if (suggestion.type == null) { suggestion.type = type }
         sanitizedSuggestions.push(suggestion)
       }
     }
     return sanitizedSuggestions
   } else {
     return null
   }
 }
Пример #7
0
  constructor (params = {}) {
    this.id = (params.id != null) ? params.id : nextId++

    // Public: A {Clipboard} instance
    this.clipboard = params.clipboard
    this.updateProcessEnv = params.updateProcessEnv || updateProcessEnv
    this.enablePersistence = params.enablePersistence
    this.applicationDelegate = params.applicationDelegate

    this.nextProxyRequestId = 0
    this.unloading = false
    this.loadTime = null
    this.emitter = new Emitter()
    this.disposables = new CompositeDisposable()
    this.pathsWithWaitSessions = new Set()

    // Public: A {DeserializerManager} instance
    this.deserializers = new DeserializerManager(this)
    this.deserializeTimings = {}

    // Public: A {ViewRegistry} instance
    this.views = new ViewRegistry(this)

    // Public: A {NotificationManager} instance
    this.notifications = new NotificationManager()

    this.stateStore = new StateStore('AtomEnvironments', 1)

    // Public: A {Config} instance
    this.config = new Config({
      saveCallback: settings => {
        if (this.enablePersistence) {
          this.applicationDelegate.setUserSettings(settings, this.config.getUserConfigPath())
        }
      }
    })
    this.config.setSchema(null, {type: 'object', properties: _.clone(ConfigSchema)})

    // Public: A {KeymapManager} instance
    this.keymaps = new KeymapManager({notificationManager: this.notifications})

    // Public: A {TooltipManager} instance
    this.tooltips = new TooltipManager({keymapManager: this.keymaps, viewRegistry: this.views})

    // Public: A {CommandRegistry} instance
    this.commands = new CommandRegistry()
    this.uriHandlerRegistry = new URIHandlerRegistry()

    // Public: A {GrammarRegistry} instance
    this.grammars = new GrammarRegistry({config: this.config})

    // Public: A {StyleManager} instance
    this.styles = new StyleManager()

    // Public: A {PackageManager} instance
    this.packages = new PackageManager({
      config: this.config,
      styleManager: this.styles,
      commandRegistry: this.commands,
      keymapManager: this.keymaps,
      notificationManager: this.notifications,
      grammarRegistry: this.grammars,
      deserializerManager: this.deserializers,
      viewRegistry: this.views,
      uriHandlerRegistry: this.uriHandlerRegistry
    })

    // Public: A {ThemeManager} instance
    this.themes = new ThemeManager({
      packageManager: this.packages,
      config: this.config,
      styleManager: this.styles,
      notificationManager: this.notifications,
      viewRegistry: this.views
    })

    // Public: A {MenuManager} instance
    this.menu = new MenuManager({keymapManager: this.keymaps, packageManager: this.packages})

    // Public: A {ContextMenuManager} instance
    this.contextMenu = new ContextMenuManager({keymapManager: this.keymaps})

    this.packages.setMenuManager(this.menu)
    this.packages.setContextMenuManager(this.contextMenu)
    this.packages.setThemeManager(this.themes)

    // Public: A {Project} instance
    this.project = new Project({
      notificationManager: this.notifications,
      packageManager: this.packages,
      grammarRegistry: this.grammars,
      config: this.config,
      applicationDelegate: this.applicationDelegate
    })
    this.commandInstaller = new CommandInstaller(this.applicationDelegate)
    this.protocolHandlerInstaller = new ProtocolHandlerInstaller()

    // Public: A {TextEditorRegistry} instance
    this.textEditors = new TextEditorRegistry({
      config: this.config,
      grammarRegistry: this.grammars,
      assert: this.assert.bind(this),
      packageManager: this.packages
    })

    // Public: A {Workspace} instance
    this.workspace = new Workspace({
      config: this.config,
      project: this.project,
      packageManager: this.packages,
      grammarRegistry: this.grammars,
      deserializerManager: this.deserializers,
      notificationManager: this.notifications,
      applicationDelegate: this.applicationDelegate,
      viewRegistry: this.views,
      assert: this.assert.bind(this),
      textEditorRegistry: this.textEditors,
      styleManager: this.styles,
      enablePersistence: this.enablePersistence
    })

    this.themes.workspace = this.workspace

    this.autoUpdater = new AutoUpdateManager({applicationDelegate: this.applicationDelegate})

    if (this.keymaps.canLoadBundledKeymapsFromMemory()) {
      this.keymaps.loadBundledKeymaps()
    }

    this.registerDefaultCommands()
    this.registerDefaultOpeners()
    this.registerDefaultDeserializers()

    this.windowEventHandler = new WindowEventHandler({atomEnvironment: this, applicationDelegate: this.applicationDelegate})

    // Public: A {HistoryManager} instance
    this.history = new HistoryManager({project: this.project, commands: this.commands, stateStore: this.stateStore})

    // Keep instances of HistoryManager in sync
    this.disposables.add(this.history.onDidChangeProjects(event => {
      if (!event.reloaded) this.applicationDelegate.didChangeHistoryManager()
    }))
  }