mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-24 09:35:37 -05:00
Refresh master with initial release/0.24 snapshot (#332)
* Initial port of release/0.24 source code * Fix additional headers * Fix a typo in launch.json
This commit is contained in:
@@ -8,19 +8,13 @@ import URI from 'vs/base/common/uri';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { normalize } from 'vs/base/common/paths';
|
||||
import { delta } from 'vs/base/common/arrays';
|
||||
import { relative, basename } from 'path';
|
||||
import { Workspace } from 'vs/platform/workspace/common/workspace';
|
||||
import { IResourceEdit } from 'vs/editor/common/services/bulkEdit';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { fromRange, EndOfLine } from 'vs/workbench/api/node/extHostTypeConverters';
|
||||
import { relative, dirname } from 'path';
|
||||
import { Workspace, WorkspaceFolder } from 'vs/platform/workspace/common/workspace';
|
||||
import { IWorkspaceData, ExtHostWorkspaceShape, MainContext, MainThreadWorkspaceShape, IMainContext } from './extHost.protocol';
|
||||
import * as vscode from 'vscode';
|
||||
import { compare } from 'vs/base/common/strings';
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import { Disposable } from 'vs/workbench/api/node/extHostTypes';
|
||||
import { TrieMap } from 'vs/base/common/map';
|
||||
import { CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
import { Progress } from 'vs/platform/progress/common/progress';
|
||||
import { TernarySearchTree } from 'vs/base/common/map';
|
||||
import { IRelativePattern } from 'vs/base/common/glob';
|
||||
|
||||
class Workspace2 extends Workspace {
|
||||
|
||||
@@ -28,42 +22,30 @@ class Workspace2 extends Workspace {
|
||||
return data ? new Workspace2(data) : null;
|
||||
}
|
||||
|
||||
private readonly _folder: vscode.WorkspaceFolder[] = [];
|
||||
private readonly _structure = new TrieMap<vscode.WorkspaceFolder>(s => s.split('/'));
|
||||
private readonly _workspaceFolders: vscode.WorkspaceFolder[] = [];
|
||||
private readonly _structure = TernarySearchTree.forPaths<vscode.WorkspaceFolder>();
|
||||
|
||||
private constructor(data: IWorkspaceData) {
|
||||
super(data.id, data.name, data.roots);
|
||||
super(data.id, data.name, data.folders.map(folder => new WorkspaceFolder(folder)));
|
||||
|
||||
// setup the workspace folder data structure
|
||||
this.roots.forEach((uri, index) => {
|
||||
const folder = {
|
||||
name: basename(uri.fsPath),
|
||||
uri,
|
||||
index
|
||||
};
|
||||
this._folder.push(folder);
|
||||
this._structure.insert(folder.uri.toString(), folder);
|
||||
this.folders.forEach(({ name, uri, index }) => {
|
||||
const workspaceFolder = { name, uri, index };
|
||||
this._workspaceFolders.push(workspaceFolder);
|
||||
this._structure.set(workspaceFolder.uri.toString(), workspaceFolder);
|
||||
});
|
||||
}
|
||||
|
||||
get folders(): vscode.WorkspaceFolder[] {
|
||||
return this._folder.slice(0);
|
||||
get workspaceFolders(): vscode.WorkspaceFolder[] {
|
||||
return this._workspaceFolders.slice(0);
|
||||
}
|
||||
|
||||
getWorkspaceFolder(uri: URI): vscode.WorkspaceFolder {
|
||||
let str = uri.toString();
|
||||
let folder = this._structure.lookUp(str);
|
||||
if (folder) {
|
||||
// `uri` is a workspace folder so we
|
||||
let parts = str.split('/');
|
||||
while (parts.length) {
|
||||
if (parts.pop()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
str = parts.join('/');
|
||||
getWorkspaceFolder(uri: URI, resolveParent?: boolean): vscode.WorkspaceFolder {
|
||||
if (resolveParent && this._structure.get(uri.toString())) {
|
||||
// `uri` is a workspace folder so we check for its parent
|
||||
uri = uri.with({ path: dirname(uri.path) });
|
||||
}
|
||||
return this._structure.findSubstr(str);
|
||||
return this._structure.findSubstr(uri.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,15 +74,15 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape {
|
||||
if (!this._workspace) {
|
||||
return undefined;
|
||||
} else {
|
||||
return this._workspace.folders.slice(0);
|
||||
return this._workspace.workspaceFolders.slice(0);
|
||||
}
|
||||
}
|
||||
|
||||
getWorkspaceFolder(uri: vscode.Uri): vscode.WorkspaceFolder {
|
||||
getWorkspaceFolder(uri: vscode.Uri, resolveParent?: boolean): vscode.WorkspaceFolder {
|
||||
if (!this._workspace) {
|
||||
return undefined;
|
||||
}
|
||||
return this._workspace.getWorkspaceFolder(<URI>uri);
|
||||
return this._workspace.getWorkspaceFolder(uri, resolveParent);
|
||||
}
|
||||
|
||||
getPath(): string {
|
||||
@@ -110,11 +92,11 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape {
|
||||
if (!this._workspace) {
|
||||
return undefined;
|
||||
}
|
||||
const { roots } = this._workspace;
|
||||
if (roots.length === 0) {
|
||||
const { folders } = this._workspace;
|
||||
if (folders.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
return roots[0].fsPath;
|
||||
return folders[0].uri.fsPath;
|
||||
}
|
||||
|
||||
getRelativePath(pathOrUri: string | vscode.Uri, includeWorkspace?: boolean): string {
|
||||
@@ -130,24 +112,24 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape {
|
||||
return path;
|
||||
}
|
||||
|
||||
const folder = this.getWorkspaceFolder(typeof pathOrUri === 'string'
|
||||
? URI.file(pathOrUri)
|
||||
: pathOrUri
|
||||
const folder = this.getWorkspaceFolder(
|
||||
typeof pathOrUri === 'string' ? URI.file(pathOrUri) : pathOrUri,
|
||||
true
|
||||
);
|
||||
|
||||
if (!folder) {
|
||||
return normalize(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
if (typeof includeWorkspace === 'undefined') {
|
||||
includeWorkspace = this.workspace.roots.length > 1;
|
||||
includeWorkspace = this.workspace.folders.length > 1;
|
||||
}
|
||||
|
||||
let result = relative(folder.uri.fsPath, path);
|
||||
if (includeWorkspace) {
|
||||
result = `${folder.name}/${result}`;
|
||||
}
|
||||
return normalize(result);
|
||||
return normalize(result, true);
|
||||
}
|
||||
|
||||
$acceptWorkspaceData(data: IWorkspaceData): void {
|
||||
@@ -155,13 +137,12 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape {
|
||||
// keep old workspace folder, build new workspace, and
|
||||
// capture new workspace folders. Compute delta between
|
||||
// them send that as event
|
||||
const oldRoots = this._workspace ? this._workspace.folders.sort(ExtHostWorkspace._compareWorkspaceFolder) : [];
|
||||
const oldRoots = this._workspace ? this._workspace.workspaceFolders.sort(ExtHostWorkspace._compareWorkspaceFolder) : [];
|
||||
|
||||
this._workspace = Workspace2.fromData(data);
|
||||
const newRoots = this._workspace ? this._workspace.folders.sort(ExtHostWorkspace._compareWorkspaceFolder) : [];
|
||||
const newRoots = this._workspace ? this._workspace.workspaceFolders.sort(ExtHostWorkspace._compareWorkspaceFolder) : [];
|
||||
|
||||
const { added, removed } = delta(oldRoots, newRoots, ExtHostWorkspace._compareWorkspaceFolder);
|
||||
|
||||
// {{SQL CARBON EDIT}} - fix build break Argument of type 'Readonly<...
|
||||
this._onDidChangeWorkspace.fire({
|
||||
added: added,
|
||||
@@ -175,7 +156,7 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape {
|
||||
|
||||
// --- search ---
|
||||
|
||||
findFiles(include: string, exclude: string, maxResults?: number, token?: vscode.CancellationToken): Thenable<vscode.Uri[]> {
|
||||
findFiles(include: string | IRelativePattern, exclude: string | IRelativePattern, maxResults?: number, token?: vscode.CancellationToken): Thenable<vscode.Uri[]> {
|
||||
const requestId = ExtHostWorkspace._requestIdPool++;
|
||||
const result = this._proxy.$startSearch(include, exclude, maxResults, requestId);
|
||||
if (token) {
|
||||
@@ -187,73 +168,4 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape {
|
||||
saveAll(includeUntitled?: boolean): Thenable<boolean> {
|
||||
return this._proxy.$saveAll(includeUntitled);
|
||||
}
|
||||
|
||||
appyEdit(edit: vscode.WorkspaceEdit): TPromise<boolean> {
|
||||
|
||||
let resourceEdits: IResourceEdit[] = [];
|
||||
|
||||
let entries = edit.entries();
|
||||
for (let entry of entries) {
|
||||
let [uri, edits] = entry;
|
||||
|
||||
for (let edit of edits) {
|
||||
resourceEdits.push({
|
||||
resource: <URI>uri,
|
||||
newText: edit.newText,
|
||||
newEol: EndOfLine.from(edit.newEol),
|
||||
range: edit.range && fromRange(edit.range)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return this._proxy.$applyWorkspaceEdit(resourceEdits);
|
||||
}
|
||||
|
||||
// --- EXPERIMENT: workspace resolver
|
||||
|
||||
|
||||
private _handlePool = 0;
|
||||
private readonly _fsProvider = new Map<number, vscode.FileSystemProvider>();
|
||||
private readonly _searchSession = new Map<number, CancellationTokenSource>();
|
||||
|
||||
registerFileSystemProvider(authority: string, provider: vscode.FileSystemProvider): vscode.Disposable {
|
||||
const handle = ++this._handlePool;
|
||||
this._fsProvider.set(handle, provider);
|
||||
const reg = provider.onDidChange(e => this._proxy.$onFileSystemChange(handle, <URI>e));
|
||||
this._proxy.$registerFileSystemProvider(handle, authority);
|
||||
return new Disposable(() => {
|
||||
this._fsProvider.delete(handle);
|
||||
reg.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
$resolveFile(handle: number, resource: URI): TPromise<string> {
|
||||
const provider = this._fsProvider.get(handle);
|
||||
return asWinJsPromise(token => provider.resolveContents(resource));
|
||||
}
|
||||
|
||||
$storeFile(handle: number, resource: URI, content: string): TPromise<any> {
|
||||
const provider = this._fsProvider.get(handle);
|
||||
return asWinJsPromise(token => provider.writeContents(resource, content));
|
||||
}
|
||||
|
||||
$startSearch(handle: number, session: number, query: string): void {
|
||||
const provider = this._fsProvider.get(handle);
|
||||
const source = new CancellationTokenSource();
|
||||
const progress = new Progress<any>(chunk => this._proxy.$updateSearchSession(session, chunk));
|
||||
|
||||
this._searchSession.set(session, source);
|
||||
TPromise.wrap(provider.findFiles(query, progress, source.token)).then(() => {
|
||||
this._proxy.$finishSearchSession(session);
|
||||
}, err => {
|
||||
this._proxy.$finishSearchSession(session, err);
|
||||
});
|
||||
}
|
||||
|
||||
$cancelSearch(handle: number, session: number): void {
|
||||
if (this._searchSession.has(session)) {
|
||||
this._searchSession.get(session).cancel();
|
||||
this._searchSession.delete(session);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user