client.onRequest(NoSassLintLibraryRequest.type, (params) => { const uri: Uri = Uri.parse(params.source.uri); const workspaceFolder = workspace.getWorkspaceFolder(uri); const packageManager = workspace.getConfiguration("sasslint", uri).get("packageManager", "npm"); client.info(getInstallFailureMessage(uri, workspaceFolder, packageManager)); return {}; });
export function findSettingsFiles(uri?: Uri): Thenable<Uri[]> { const { workspaceFolders } = workspace; if (!workspaceFolders || !hasWorkspaceLocation()) { return Promise.resolve([]); } const folders = uri ? [workspace.getWorkspaceFolder(uri)!].filter(a => !!a) : workspaceFolders; const possibleLocations = folders .map(folder => folder.uri.fsPath) .map(root => configFileLocations.map(rel => path.join(root, rel))) .reduce((a, b) => a.concat(b)); const found = possibleLocations .map(filename => fs.pathExists(filename) .then(exists => ({ filename, exists }))); return Promise.all(found).then(found => found .filter(found => found.exists) .map(found => found.filename) .map(filename => Uri.file(filename)) ); }
private fixHref(resource: vscode.Uri, href: string): string { if (!href) { return href; } // Use href if it is already an URL const hrefUri = vscode.Uri.parse(href); if (['http', 'https'].indexOf(hrefUri.scheme) >= 0) { return hrefUri.toString(); } // Use href as file URI if it is absolute if (path.isAbsolute(href) || hrefUri.scheme === 'file') { return vscode.Uri.file(href) .with({ scheme: 'vscode-resource' }) .toString(); } // Use a workspace relative path if there is a workspace let root = vscode.workspace.getWorkspaceFolder(resource); if (root) { return vscode.Uri.file(path.join(root.uri.fsPath, href)) .with({ scheme: 'vscode-resource' }) .toString(); } // Otherwise look relative to the markdown file return vscode.Uri.file(path.join(path.dirname(resource.fsPath), href)) .with({ scheme: 'vscode-resource' }) .toString(); }
function getEditorInfo(): { text: string; tooltip: string; color: string; } { const editor = window.activeTextEditor; // If no workspace is opened or just a single folder, we return without any status label // because our extension only works when more than one folder is opened in a workspace. if (!editor || !workspace.workspaceFolders || workspace.workspaceFolders.length < 2) { return null; } let text: string; let tooltip: string; let color: string; // If we have a file:// resource we resolve the WorkspaceFolder this file is from and update // the status accordingly. const resource = editor.document.uri; if (resource.scheme === 'file') { const folder = workspace.getWorkspaceFolder(resource); if (!folder) { text = `$(alert) <outside workspace> → ${basename(resource.fsPath)}`; } else { text = `$(file-submodule) ${basename(folder.uri.fsPath)} (${folder.index + 1} of ${workspace.workspaceFolders.length}) → $(file-code) ${basename(resource.fsPath)}`; tooltip = resource.fsPath; const multiRootConfigForResource = workspace.getConfiguration('multiRootSample', resource); color = multiRootConfigForResource.get('statusColor'); } } return { text, tooltip, color }; }
private fixHref(resource: vscode.Uri, href: string): string { if (!href) { return href; } if (href.startsWith('http:') || href.startsWith('https:') || href.startsWith('file:')) { return href; } // Assume it must be a local file if (path.isAbsolute(href)) { return vscode.Uri.file(href) .with({ scheme: 'vscode-resource' }) .toString(); } // Use a workspace relative path if there is a workspace const root = vscode.workspace.getWorkspaceFolder(resource); if (root) { return vscode.Uri.file(path.join(root.uri.fsPath, href)) .with({ scheme: 'vscode-resource' }) .toString(); } // Otherwise look relative to the markdown file return vscode.Uri.file(path.join(path.dirname(resource.fsPath), href)) .with({ scheme: 'vscode-resource' }) .toString(); }
function normalizeResourceUri(uri: Uri | null | undefined): Uri | null { if (uri) { const folder = workspace.getWorkspaceFolder(uri); return folder && folder.uri || null; } return null; }
configuration: (params, token, next) => { if (!params.items) { return []; } const result = next(params, token); let scopeUri = ""; for (const item of params.items) { if (!item.scopeUri) { continue; } else { scopeUri = item.scopeUri; } } const resource = client.protocol2CodeConverter.asUri(scopeUri); const workspaceFolder = workspace.getWorkspaceFolder(resource); if (workspaceFolder) { convertToAbsolutePaths(result[0], workspaceFolder); if (workspaceFolder.uri.scheme === "file") { result[0].workspaceFolderPath = workspaceFolder.uri.fsPath; } } return result; }
public constructor(workspaceInfo: protocol.WorkspaceInformationResponse, workspaceFolder: vscode.WorkspaceFolder = undefined) { if (workspaceFolder) { this.workspaceFolder = workspaceFolder; } else { let resourcePath: string = undefined; if (!resourcePath && workspaceInfo.Cake) { resourcePath = workspaceInfo.Cake.Path; } if (!resourcePath && workspaceInfo.ScriptCs) { resourcePath = workspaceInfo.ScriptCs.Path; } if (!resourcePath && workspaceInfo.DotNet && workspaceInfo.DotNet.Projects.length > 0) { resourcePath = workspaceInfo.DotNet.Projects[0].Path; } if (!resourcePath && workspaceInfo.MsBuild) { resourcePath = workspaceInfo.MsBuild.SolutionPath; } this.workspaceFolder = vscode.workspace.getWorkspaceFolder(vscode.Uri.file(resourcePath)); } this.vscodeFolder = path.join(this.workspaceFolder.uri.fsPath, '.vscode'); this.tasksJsonPath = path.join(this.vscodeFolder, 'tasks.json'); this.launchJsonPath = path.join(this.vscodeFolder, 'launch.json'); this.initializeProjectData(workspaceInfo); }
async function provideNpmScriptsForFolder(packageJsonUri: Uri): Promise<Task[]> { let emptyTasks: Task[] = []; let folder = workspace.getWorkspaceFolder(packageJsonUri); if (!folder) { return emptyTasks; } let scripts = await getScripts(packageJsonUri); if (!scripts) { return emptyTasks; } const result: Task[] = []; Object.keys(scripts).filter(isNotPreOrPostScript).forEach(each => { const task = createTask(each, `run ${each}`, folder!, packageJsonUri); const lowerCaseTaskName = each.toLowerCase(); if (isBuildTask(lowerCaseTaskName)) { task.group = TaskGroup.Build; } else if (isTestTask(lowerCaseTaskName)) { task.group = TaskGroup.Test; } result.push(task); }); // always add npm install (without a problem matcher) result.push(createTask('install', 'install', folder, packageJsonUri, [])); return result; }
md.normalizeLink = (link: string) => { try { let uri = vscode.Uri.parse(link); if (!uri.scheme && uri.path) { // Assume it must be a file const fragment = uri.fragment; if (uri.path[0] === '/') { const root = vscode.workspace.getWorkspaceFolder(this.currentDocument!); if (root) { uri = vscode.Uri.file(path.join(root.uri.fsPath, uri.path)); } } else { uri = vscode.Uri.file(path.join(path.dirname(this.currentDocument!.path), uri.path)); } if (fragment) { uri = uri.with({ fragment: Slug.fromHeading(fragment).value }); } return normalizeLink(uri.with({ scheme: 'vscode-resource' }).toString(true)); } else if (!uri.scheme && !uri.path && uri.fragment) { return normalizeLink(uri.with({ fragment: Slug.fromHeading(uri.fragment).value }).toString(true)); } } catch (e) { // noop } return normalizeLink(link); };