本文整理汇总了TypeScript中atom.TextBuffer.getUri方法的典型用法代码示例。如果您正苦于以下问题:TypeScript TextBuffer.getUri方法的具体用法?TypeScript TextBuffer.getUri怎么用?TypeScript TextBuffer.getUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atom.TextBuffer
的用法示例。
在下文中一共展示了TextBuffer.getUri方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
}
示例2: 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
}
示例3: 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')}
}
}
示例4: 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
}
示例5: lint
public async lint(buffer: TextBuffer) {
const file = buffer.getUri()
const messages = await this.backend.lint([file])
return this.convertMessages(messages)
}