Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public sync({ sync: query }: merlin.Sync, id?: LSP.TextDocumentIdentifier): merlin.Response {
// this.session.connection.console.log(
// JSON.stringify({ query, id, priority }),
// );
const context: ["auto", string] | undefined = id ? ["auto", URI.parse(id.uri).fsPath] : undefined;
const request = context ? { context, query } : query;
return new Promise(resolve => {
const task = new merlin.Task(request);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const callback: async.AsyncResultArrayCallback<i> = (value: any) => {
resolve(null == value ? undefined : value);
};
this.queue.push(task, 0, callback);
});
}
</i>
if (null == localappdataFile) throw new Error("LOCALAPPDATA must be set in environment to interpret WSL /home");
// FIXME: compute localappdata earlier and do it only once
const localappdata = URI.file(localappdataFile).toString(skipEncoding);
let match: RegExpMatchArray | null = null;
// rewrite /mnt/…
if (null != (match = uri.match(/^file:\/\/\/mnt\/([a-zA-Z])\/(.*)$/))) {
match.shift();
const drive = match.shift() as string;
const rest = match.shift() as string;
return URI.parse(`file:///${drive}:/${rest}`);
}
// rewrite /home/…
if (null != (match = uri.match(/^file:\/\/\/home\/(.+)$/))) {
match.shift();
const rest = match.shift() as string;
return URI.parse(`${localappdata}/lxss/home/${rest}`);
}
throw new Error("unreachable");
};
switch (this.source) {
function testUriPath(uriPath: string): boolean {
const uri = Uri.parse(uriPath);
return testUri(uri);
}
return testUriPath;
private resolveConfigImports(config: CSpellUserSettings, folderUri: string): CSpellUserSettings {
const uriFsPath = Uri.parse(folderUri).fsPath;
const imports = typeof config.import === 'string' ? [config.import] : config.import || [];
if (!imports.length) {
return config;
}
const importAbsPath = imports.map(file => path.resolve(file, uriFsPath));
return CSpell.mergeSettings(CSpell.readSettingsFiles(importAbsPath), config);
}
}
function configPathsForRoot(workspaceRootUri?: string) {
const workspaceRoot = workspaceRootUri ? Uri.parse(workspaceRootUri).fsPath : '';
const paths = workspaceRoot ? [
path.join(workspaceRoot, '.vscode', CSpell.defaultSettingsFilename.toLowerCase()),
path.join(workspaceRoot, '.vscode', CSpell.defaultSettingsFilename),
path.join(workspaceRoot, '.' + CSpell.defaultSettingsFilename.toLowerCase()),
path.join(workspaceRoot, CSpell.defaultSettingsFilename.toLowerCase()),
path.join(workspaceRoot, CSpell.defaultSettingsFilename),
] : [];
return paths;
}
let { nvim } = this
let doc = this.getDocument(uri)
let bufnr = doc ? doc.bufnr : -1
await nvim.command(`normal! m'`)
if (bufnr == this.bufnr && jumpCommand == 'edit') {
if (position) await this.moveTo(position)
} else if (bufnr != -1 && jumpCommand == 'edit') {
let moveCmd = ''
if (position) {
let line = doc.getline(position.line)
let col = byteLength(line.slice(0, position.character)) + 1
moveCmd = position ? `+call\\ cursor(${position.line + 1},${col})` : ''
}
await this.nvim.call('coc#util#execute', [`buffer ${moveCmd} ${bufnr}`])
} else {
let { fsPath, scheme } = URI.parse(uri)
let pos = position == null ? null : [position.line + 1, position.character + 1]
if (scheme == 'file') {
let bufname = fixDriver(path.normalize(fsPath))
await this.nvim.call('coc#util#jump', [jumpCommand, bufname, pos])
} else {
await this.nvim.call('coc#util#jump', [jumpCommand, uri, pos])
}
}
}
affectsConfiguration: (section, resource) => {
if (!resource || target != ConfigurationTarget.Workspace) return changed.indexOf(section) !== -1
let u = URI.parse(resource)
if (u.scheme !== 'file') return changed.indexOf(section) !== -1
let filepath = u.fsPath
let preRoot = workspaceConfigFile ? path.resolve(workspaceConfigFile, '../..') : ''
if (configFile && !isParentFolder(preRoot, filepath, true) && !isParentFolder(path.resolve(configFile, '../..'), filepath)) {
return false
}
return changed.indexOf(section) !== -1
}
})
public getDocument(uri: number | string): Document {
if (typeof uri === 'number') {
return this.buffers.get(uri)
}
uri = URI.parse(uri).toString()
for (let doc of this.buffers.values()) {
if (doc && doc.uri === uri) return doc
}
return null
}
function uriToPath(stringUri) {
const uri = URI.parse(stringUri);
if (uri.scheme !== 'file') {
return undefined;
}
return uri.fsPath;
}