Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async showSignatureHelp(): Promise {
if (this.signatureTokenSource) {
this.signatureTokenSource.cancel()
this.signatureTokenSource.dispose()
this.signatureTokenSource = null
}
let document = workspace.getDocument(workspace.bufnr)
if (!document) return
let position = await workspace.getCursorPosition()
let part = document.getline(position.line).slice(0, position.character)
if (/\)\s*$/.test(part)) return
let idx = Math.max(part.lastIndexOf(','), part.lastIndexOf('('))
if (idx != -1) position.character = idx + 1
let tokenSource = this.signatureTokenSource = new CancellationTokenSource()
let token = tokenSource.token
let timer = setTimeout(() => {
if (!token.isCancellationRequested) {
tokenSource.cancel()
}
}, 3000)
let signatureHelp = await languages.getSignatureHelp(document.textDocument, position, token)
clearTimeout(timer)
if (token.isCancellationRequested || !signatureHelp || signatureHelp.signatures.length == 0) {
this.signatureFactory.close()
return
}
let { activeParameter, activeSignature, signatures } = signatureHelp
if (activeSignature) {
// make active first
let [active] = signatures.splice(activeSignature, 1)
public async onPumChange(ev: PopupChangeEvent): Promise {
if (!this.activated) return
if (this.document && this.document.uri.endsWith('%5BCommand%20Line%5D')) return
this.cancel()
let { completed_item, col, row, height, width, scrollbar } = ev
let bounding: PumBounding = { col, row, height, width, scrollbar }
this.currItem = completed_item.hasOwnProperty('word') ? completed_item : null
// it's pum change by vim, ignore it
if (this.lastInsert) return
let resolvedItem = this.getCompleteItem(completed_item)
if (!resolvedItem) {
this.floating.close()
return
}
let source = this.resolveTokenSource = new CancellationTokenSource()
let { token } = source
await sources.doCompleteResolve(resolvedItem, token)
if (token.isCancellationRequested) return
let docs = resolvedItem.documentation
if (!docs && resolvedItem.info) {
let { info } = resolvedItem
let isText = /^[\w-\s.,\t]+$/.test(info)
docs = [{ filetype: isText ? 'txt' : this.document.filetype, content: info }]
}
if (!docs || docs.length == 0) {
this.floating.close()
} else {
if (token.isCancellationRequested) return
await this.floating.show(docs, bounding, token)
}
this.resolveTokenSource = null
private async completeSource(source: ISource): Promise {
let { col } = this.option
// new option for each source
let opt = Object.assign({}, this.option)
let timeout = this.config.timeout
timeout = Math.max(Math.min(timeout, 5000), 1000)
try {
if (typeof source.shouldComplete === 'function') {
let shouldRun = await Promise.resolve(source.shouldComplete(opt))
if (!shouldRun) return null
}
let start = Date.now()
let oldSource = this.tokenSources.get(source.name)
if (oldSource) oldSource.cancel()
let tokenSource = new CancellationTokenSource()
this.tokenSources.set(source.name, tokenSource)
await new Promise((resolve, reject) => {
let { name } = source
let timer = setTimeout(() => {
this.nvim.command(`echohl WarningMsg| echom 'source ${source.name} timeout after ${timeout}ms'|echohl None`, true)
tokenSource.cancel()
}, timeout)
let cancelled = false
let called = false
let empty = false
let ft = setTimeout(() => {
if (called) return
empty = true
resolve()
}, FIRST_TIMEOUT)
let onFinished = () => {
private async triggerSignatureHelp(document: Document, position: Position): Promise {
if (this.signatureTokenSource) {
this.signatureTokenSource.cancel()
this.signatureTokenSource = null
}
let part = document.getline(position.line).slice(0, position.character)
if (part.endsWith(')')) {
this.signatureFactory.close()
return
}
let idx = Math.max(part.lastIndexOf(','), part.lastIndexOf('('))
if (idx != -1) position.character = idx + 1
let tokenSource = this.signatureTokenSource = new CancellationTokenSource()
let token = tokenSource.token
let timer = setTimeout(() => {
if (!token.isCancellationRequested) {
tokenSource.cancel()
}
}, 3000)
let signatureHelp = await languages.getSignatureHelp(document.textDocument, position, token)
clearTimeout(timer)
if (token.isCancellationRequested || !signatureHelp || signatureHelp.signatures.length == 0) {
this.signatureFactory.close()
return false
}
let { activeParameter, activeSignature, signatures } = signatureHelp
if (activeSignature) {
// make active first
let [active] = signatures.splice(activeSignature, 1)
import { ISettings } from "../../../lib";
import { Merlin } from "../processes";
import Analyzer from "./analyzer";
import Environment from "./environment";
import Indexer from "./indexer";
import Synchronizer from "./synchronizer";
export { Environment };
export type CancellationSources = "analyzer/refreshWithKind";
export default class Session implements LSP.Disposable {
public readonly analyzer: Analyzer;
public readonly cancellationSources: { readonly [S in CancellationSources]: LSP.CancellationTokenSource } = {
"analyzer/refreshWithKind": new LSP.CancellationTokenSource(),
};
public readonly connection: server.IConnection = server.createConnection();
public readonly environment: Environment;
public readonly indexer: Indexer;
public readonly initConf: LSP.InitializeParams;
public readonly merlin: Merlin;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public readonly settings: ISettings = {} as any;
public readonly synchronizer: Synchronizer;
constructor() {
this.analyzer = new Analyzer(this);
this.environment = new Environment(this);
this.indexer = new Indexer(this);
this.merlin = new Merlin(this);
this.synchronizer = new Synchronizer(this);
private async onBufReadCmd(scheme: string, uri: string): Promise {
let provider = this.schemeProviderMap.get(scheme)
if (!provider) {
this.showMessage(`Provider for ${scheme} not found`, 'error')
return
}
let tokenSource = new CancellationTokenSource()
let content = await Promise.resolve(provider.provideTextDocumentContent(URI.parse(uri), tokenSource.token))
let buf = await this.nvim.buffer
await buf.setLines(content.split('\n'), {
start: 0,
end: -1,
strictIndexing: false
})
setTimeout(async () => {
await events.fire('BufCreate', [buf.id])
}, 30)
}
public async loadItems(reload = false): Promise {
let { context, list, listOptions } = this.manager
if (!list) return
this.loadMru()
if (this.timer) clearTimeout(this.timer)
this.loading = true
let { interactive } = listOptions
let source = this.tokenSource = new CancellationTokenSource()
let token = source.token
let items = await list.loadItems(context, token)
if (token.isCancellationRequested) return
if (!items || Array.isArray(items)) {
items = (items || []) as ListItem[]
this.totalItems = items.map(item => {
item.label = this.fixLabel(item.label)
this.parseListItemAnsi(item)
return item
})
this.loading = false
let highlights: ListHighlights[] = []
if (!interactive) {
let res = this.filterItems(items)
items = res.items
highlights = res.highlights
constructor(private _connection: ProgressContext, private _token: ProgressToken) {
WorkDoneProgressImpl.Instances.set(this._token, this);
this._source = new CancellationTokenSource();
}
private get token(): CancellationToken {
this.cancelTokenSource = new CancellationTokenSource()
return this.cancelTokenSource.token
}