當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript atom.TextBuffer類代碼示例

本文整理匯總了TypeScript中atom.TextBuffer的典型用法代碼示例。如果您正苦於以下問題:TypeScript TextBuffer類的具體用法?TypeScript TextBuffer怎麽用?TypeScript TextBuffer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TextBuffer類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: registerCompletionBuffer

  /*
  registerCompletionBuffer(buffer)
  Every buffer that would be used with autocompletion functions has to
  be registered with this function.

  buffer: TextBuffer, buffer to be used in autocompletion

  Returns: Disposable, which will remove buffer from autocompletion
  */
  public registerCompletionBuffer(buffer: TextBuffer) {
    if (!this.isActive) { throw new Error('Backend inactive') }

    if (this.bufferMap.has(buffer)) {
      return new Disposable(() => { /* void */ })
    }

    this.bufferMap.set(buffer, new BufferInfo(buffer))

    const file = buffer.getUri()
    buffer.onDidSave(async (_event) => {
      const buf: BufferInfo | undefined = this.bufferMap.get(buffer)
      if (buf) {
        delete buf.completions
      }
      const contents: string = buffer.getText()
      await this.process.backend.setFileContents(file, contents)
      await this.process.backend.scanFile({ file, scanProject: false, scanDeps: false })
    })

    setImmediate(async () => {
      this.process.backend.scanFile({ file })
    })

    return new Disposable(() =>
      this.unregisterCompletionBuffer(buffer))
  }
開發者ID:mvoidex,項目名稱:atom-haskell-hsdev,代碼行數:36,代碼來源:index.ts

示例2: resolve

  const buffer = await new Promise<TextBuffer.ITextBuffer>(resolve => {
    const buffer = new Atom.TextBuffer({
      filePath,
      load: true,
    })

    buffer.onDidReload(() => {
      resolve(buffer)
    })
  })
開發者ID:GavinJoyce,項目名稱:dotfiles,代碼行數:10,代碼來源:atomts.ts

示例3: getCompletionsForSymbolInModule

  /*
  getCompletionsForSymbolInModule(buffer,prefix,position,{module})
  Used in import hiding/list completions

  buffer: TextBuffer, current buffer
  prefix: String, completion prefix
  position: Point, current cursor position
  module: String, module name (optional). If undefined, function
          will attempt to infer module name from position and buffer.

  Returns: Promise([symbol])
  symbol: Object, symbol in given module
    name: String, symbol name
    typeSignature: String, type signature
    symbolType: String, one of ['type', 'class', 'function']
  */
  public async getCompletionsForSymbolInModule(
    buffer: TextBuffer, prefix: string, position: Point,
    opts?: { module: string },
  ): Promise<CB.ISymbol[]> {
    if (!this.isActive) { throw new Error('Backend inactive') }
    let moduleName = opts ? opts.module : undefined
    if (!moduleName) {
      const lineRange = new Range([0, position.row], position)
      buffer.backwardsScanInRange(
        /^import\s+([\w.]+)/,
        lineRange, ({ match }) => moduleName = match[1],
      )
    }

    return [] // TODO: Implement
    // tslint:enable: no-null-keyword
    // return FZ.filter(symbols, prefix, { key: 'name' })
  }
開發者ID:mvoidex,項目名稱:atom-haskell-hsdev,代碼行數:34,代碼來源:index.ts

示例4: getCompletionsForModule

  /*
  getCompletionsForModule(buffer,prefix,position)
  buffer: TextBuffer, current buffer
  prefix: String, completion prefix
  position: Point, current cursor position

  Returns: Promise([module])
  module: String, module name
  */
  public async getCompletionsForModule(
    buffer: TextBuffer, prefix: string, _position: Point,
  ): Promise<string[]> {
    if (!this.isActive) { throw new Error('Backend inactive') }
    const modules = await this.process.backend.scopeModules({
      query: prefix,
      searchType: 'prefix',
      file: buffer.getUri(),
    })
    const parts: number = prefix.split('.').length
    const names: string[] = []
    for (const m of modules) {
      if (m.name.split('.').length == parts) {
        names.push(m.name)
      }
    }
    return names
  }
開發者ID:mvoidex,項目名稱:atom-haskell-hsdev,代碼行數:27,代碼來源:index.ts

示例5: whoat

  public async whoat(
    buffer: TextBuffer, crange: Range
  ) {
    const file = buffer.getUri()
    const line = crange.start.row + 1
    const column = crange.start.column + 1
    const symbols: any[] = await this.backend.whoat(file, line, column)
    if (symbols.length == 0) {
      Util.debug(`No info found for symbol at ${file} ${line} ${column}`)
      throw Error(`No info found for symbol at ${file} ${line} ${column}`)
    }
    else {
      const sym = symbols[0]
      const what = sym.info.what
      const lines = []
      switch (what) {
        case 'function':
        case 'method':
        case 'constructor':
          lines.push(`${sym.id.name} :: ${sym.info.type ? sym.info.type : '?'}`)
          break
        case 'data':
        case 'type':
        case 'class':
        case 'newtype':
          lines.push(`${what} ${sym.id.name}`)
          break
        default:
          lines.push(`${sym.id.name}`)
      }

      if (sym.docs) {
        lines.push('', `{- ${sym.docs} -}`)
      }

      if (sym.id.module.location.file && sym.pos) {
        lines.push('', `-- Defined in ${sym.id.module.location.file}:${sym.pos.line}:${sym.pos.column}`)
      }
      return {range: crange, info: lines.join('\n')}
    }
  }
開發者ID:mvoidex,項目名稱:atom-haskell-hsdev,代碼行數:41,代碼來源:index.ts

示例6: getCompletionsForBuffer

  private async getCompletionsForBuffer(
    buffer: TextBuffer, symbolTypes?: CB.SymbolType[],
  ): Promise<CB.ISymbol[]> {
    let symbols: CB.ISymbol[] = []

    const buf: BufferInfo | undefined = this.bufferMap.get(buffer)
    if (buf && buf.completions) {
      symbols = buf.completions
    }
    else {
      const comps: any[] = await this.process.backend.complete(
        '',
        buffer.getUri(),
      )
      for (const comp of comps) {
        let symType: CB.SymbolType = 'function'
        switch (comp.info.what) {
          case 'function':
          case 'method':
          case 'selector':
          case 'pat-selector':
          case 'pat-constructor':
          case 'constructor':
            symType = 'function'
            break
          case 'type':
          case 'newtype':
          case 'data':
          case 'type-family':
          case 'data-family':
            symType = 'type'
            break
          case 'class':
            symType = 'class'
            break
          default:
            break
        }
        if (symbolTypes && !(symType in symbolTypes)) {
          continue
        }

        symbols.push({
          qparent: comp.qualifier,
          qname: comp.qualifier ? `${comp.qualifier}.${comp.id.name}` : comp.id.name,
          name: comp.id.name,
          symbolType: symType,
          typeSignature: comp.info.type,
          // FIXME: Use import module
          module: {
            name: comp.id.module.name,
            hiding: false,
            qualified: false,
            alias: null,
            importList: null,
          }
        })
      }
      if (buf) {
        Util.debug(`Caching ${symbols.length} completions for ${buffer.getUri()}`)
        buf.completions = symbols
      }
    }
    if (!symbolTypes) {
      return symbols
    }
    const result: CB.ISymbol[] = []
    for (const sym of symbols) {
      if (sym.symbolType in symbolTypes) {
        result.push(sym)
      }
    }
    return result
  }
開發者ID:mvoidex,項目名稱:atom-haskell-hsdev,代碼行數:74,代碼來源:index.ts

示例7: lint

 public async lint(buffer: TextBuffer) {
   const file = buffer.getUri()
   const messages = await this.backend.lint([file])
   return this.convertMessages(messages)
 }
開發者ID:mvoidex,項目名稱:atom-haskell-hsdev,代碼行數:5,代碼來源:index.ts

示例8:

 buffer.onDidSave(async (_event) => {
   const buf: BufferInfo | undefined = this.bufferMap.get(buffer)
   if (buf) {
     delete buf.completions
   }
   const contents: string = buffer.getText()
   await this.process.backend.setFileContents(file, contents)
   await this.process.backend.scanFile({ file, scanProject: false, scanDeps: false })
 })
開發者ID:mvoidex,項目名稱:atom-haskell-hsdev,代碼行數:9,代碼來源:index.ts


注:本文中的atom.TextBuffer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。