mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
maintain scheme in insights (#10904)
* maintain scheme in insights * fix compiles * fix tests * handle undefined * fix windows tests * fix imports * handle remote resources
This commit is contained in:
@@ -313,9 +313,9 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
|
|||||||
if (types.isStringArray(this.insightConfig.query)) {
|
if (types.isStringArray(this.insightConfig.query)) {
|
||||||
this.insightConfig.query = this.insightConfig.query.join(' ');
|
this.insightConfig.query = this.insightConfig.query.join(' ');
|
||||||
} else if (this.insightConfig.queryFile) {
|
} else if (this.insightConfig.queryFile) {
|
||||||
const filePath = await this.instantiationService.invokeFunction(resolveQueryFilePath, this.insightConfig.queryFile);
|
const fileUri: URI = await this.instantiationService.invokeFunction(resolveQueryFilePath, this.insightConfig.queryFile);
|
||||||
|
|
||||||
this.insightConfig.query = (await this.fileService.readFile(URI.file(filePath))).value.toString();
|
this.insightConfig.query = (await this.fileService.readFile(fileUri)).value.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ export class InsightsDialogController {
|
|||||||
this._errorMessageService.showDialog(Severity.Error, nls.localize("insightsError", "Insights error"), e);
|
this._errorMessageService.showDialog(Severity.Error, nls.localize("insightsError", "Insights error"), e);
|
||||||
}).then(() => undefined);
|
}).then(() => undefined);
|
||||||
} else if (types.isString(input.queryFile)) {
|
} else if (types.isString(input.queryFile)) {
|
||||||
let filePath: string;
|
let fileUri: URI;
|
||||||
try {
|
try {
|
||||||
filePath = await this._instantiationService.invokeFunction(resolveQueryFilePath, input.queryFile);
|
fileUri = await this._instantiationService.invokeFunction(resolveQueryFilePath, input.queryFile);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
this._notificationService.notify({
|
this._notificationService.notify({
|
||||||
@@ -71,7 +71,7 @@ export class InsightsDialogController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let buffer = await this.fileService.readFile(URI.file(filePath));
|
let buffer = await this.fileService.readFile(fileUri);
|
||||||
this.createQuery(buffer.value.toString(), connectionProfile).catch(e => {
|
this.createQuery(buffer.value.toString(), connectionProfile).catch(e => {
|
||||||
this._errorMessageService.showDialog(Severity.Error, nls.localize("insightsError", "Insights error"), e);
|
this._errorMessageService.showDialog(Severity.Error, nls.localize("insightsError", "Insights error"), e);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { IConfigurationResolverService } from 'vs/workbench/services/configurati
|
|||||||
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||||
import { IFileService } from 'vs/platform/files/common/files';
|
import { IFileService } from 'vs/platform/files/common/files';
|
||||||
import { URI } from 'vs/base/common/uri';
|
import { URI } from 'vs/base/common/uri';
|
||||||
|
import { Schemas } from 'vs/base/common/network';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the given file path using the VS ConfigurationResolver service, replacing macros such as
|
* Resolves the given file path using the VS ConfigurationResolver service, replacing macros such as
|
||||||
@@ -19,9 +20,11 @@ import { URI } from 'vs/base/common/uri';
|
|||||||
* @param workspaceContextService The workspace context to use for resolving workspace vars
|
* @param workspaceContextService The workspace context to use for resolving workspace vars
|
||||||
* @param configurationResolverService The resolver service to use to resolve the vars
|
* @param configurationResolverService The resolver service to use to resolve the vars
|
||||||
*/
|
*/
|
||||||
export async function resolveQueryFilePath(services: ServicesAccessor, filePath: string): Promise<string> {
|
export async function resolveQueryFilePath(services: ServicesAccessor, filePath: undefined): Promise<undefined>;
|
||||||
|
export async function resolveQueryFilePath(services: ServicesAccessor, filePath: string): Promise<URI>;
|
||||||
|
export async function resolveQueryFilePath(services: ServicesAccessor, filePath?: string): Promise<URI | undefined> {
|
||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
return filePath;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const workspaceContextService = services.get(IWorkspaceContextService);
|
const workspaceContextService = services.get(IWorkspaceContextService);
|
||||||
@@ -31,15 +34,25 @@ export async function resolveQueryFilePath(services: ServicesAccessor, filePath:
|
|||||||
let workspaceFolders: IWorkspaceFolder[] = workspaceContextService.getWorkspace().folders;
|
let workspaceFolders: IWorkspaceFolder[] = workspaceContextService.getWorkspace().folders;
|
||||||
// Resolve the path using each folder in our workspace, or undefined if there aren't any
|
// Resolve the path using each folder in our workspace, or undefined if there aren't any
|
||||||
// (so that non-folder vars such as environment vars still resolve)
|
// (so that non-folder vars such as environment vars still resolve)
|
||||||
let resolvedFilePaths = (workspaceFolders.length > 0 ? workspaceFolders : [undefined])
|
const isRemote = fileService.canHandleResource(URI.from({ scheme: Schemas.vscodeRemote }));
|
||||||
.map(f => configurationResolverService.resolve(f, filePath));
|
let resolvedFileUris = (workspaceFolders.length > 0 ? workspaceFolders : [undefined])
|
||||||
|
.map(f => {
|
||||||
|
const uri = URI.file(configurationResolverService.resolve(f, filePath));
|
||||||
|
if (f) {
|
||||||
|
return uri.with({ scheme: f.uri.scheme }); // ensure we maintain the correct scheme
|
||||||
|
} else if (isRemote) {
|
||||||
|
return uri.with({ scheme: Schemas.vscodeRemote });
|
||||||
|
} else {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Just need a single query file so use the first we find that exists
|
// Just need a single query file so use the first we find that exists
|
||||||
for (const path of resolvedFilePaths) {
|
for (const uri of resolvedFileUris) {
|
||||||
if (await fileService.exists(URI.file(path))) {
|
if (await fileService.exists(uri)) {
|
||||||
return path;
|
return uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw Error(localize('insightsDidNotFindResolvedFile', "Could not find query file at any of the following paths :\n {0}", resolvedFilePaths.join('\n')));
|
throw Error(localize('insightsDidNotFindResolvedFile', "Could not find query file at any of the following paths :\n {0}", resolvedFileUris.join('\n')));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
import { equal, fail } from 'assert';
|
import { ok, fail } from 'assert';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
|
|
||||||
import { resolveQueryFilePath } from 'sql/workbench/services/insights/common/insightsUtils';
|
import { resolveQueryFilePath } from 'sql/workbench/services/insights/common/insightsUtils';
|
||||||
@@ -23,6 +23,7 @@ import { getRandomTestPath } from 'vs/base/test/node/testUtils';
|
|||||||
import { IProcessEnvironment } from 'vs/base/common/platform';
|
import { IProcessEnvironment } from 'vs/base/common/platform';
|
||||||
import { NativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-browser/environmentService';
|
import { NativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-browser/environmentService';
|
||||||
import { TestWindowConfiguration } from 'vs/workbench/test/electron-browser/workbenchTestServices';
|
import { TestWindowConfiguration } from 'vs/workbench/test/electron-browser/workbenchTestServices';
|
||||||
|
import { isEqual } from 'vs/base/common/resources';
|
||||||
|
|
||||||
class MockWorkbenchEnvironmentService extends NativeWorkbenchEnvironmentService {
|
class MockWorkbenchEnvironmentService extends NativeWorkbenchEnvironmentService {
|
||||||
|
|
||||||
@@ -71,7 +72,7 @@ suite('Insights Utils tests', function () {
|
|||||||
instantiationService.set(IFileService, fileService);
|
instantiationService.set(IFileService, fileService);
|
||||||
|
|
||||||
const resolvedPath = await instantiationService.invokeFunction(resolveQueryFilePath, queryFilePath);
|
const resolvedPath = await instantiationService.invokeFunction(resolveQueryFilePath, queryFilePath);
|
||||||
equal(resolvedPath, queryFilePath);
|
ok(isEqual(resolvedPath, URI.file(queryFilePath)));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('resolveQueryFilePath resolves path correctly with workspaceRoot var and non-empty workspace containing file', async () => {
|
test('resolveQueryFilePath resolves path correctly with workspaceRoot var and non-empty workspace containing file', async () => {
|
||||||
@@ -101,7 +102,7 @@ suite('Insights Utils tests', function () {
|
|||||||
instantiationService.set(IFileService, fileService);
|
instantiationService.set(IFileService, fileService);
|
||||||
|
|
||||||
const resolvedPath = await instantiationService.invokeFunction(resolveQueryFilePath, path.join('${workspaceRoot}', 'test.sql'));
|
const resolvedPath = await instantiationService.invokeFunction(resolveQueryFilePath, path.join('${workspaceRoot}', 'test.sql'));
|
||||||
equal(resolvedPath, queryFilePath);
|
ok(isEqual(resolvedPath, URI.file(queryFilePath)));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('resolveQueryFilePath throws with workspaceRoot var and non-empty workspace not containing file', async () => {
|
test('resolveQueryFilePath throws with workspaceRoot var and non-empty workspace not containing file', async () => {
|
||||||
@@ -198,7 +199,7 @@ suite('Insights Utils tests', function () {
|
|||||||
instantiationService.set(IFileService, fileService);
|
instantiationService.set(IFileService, fileService);
|
||||||
|
|
||||||
const resolvedPath = await instantiationService.invokeFunction(resolveQueryFilePath, path.join('${env:TEST_PATH}', 'test.sql'));
|
const resolvedPath = await instantiationService.invokeFunction(resolveQueryFilePath, path.join('${env:TEST_PATH}', 'test.sql'));
|
||||||
equal(resolvedPath, queryFilePath);
|
ok(isEqual(resolvedPath, URI.file(queryFilePath)));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('resolveQueryFilePath resolves path correctly with env var and non-empty workspace', async () => {
|
test('resolveQueryFilePath resolves path correctly with env var and non-empty workspace', async () => {
|
||||||
@@ -227,7 +228,7 @@ suite('Insights Utils tests', function () {
|
|||||||
instantiationService.set(IFileService, fileService);
|
instantiationService.set(IFileService, fileService);
|
||||||
|
|
||||||
const resolvedPath = await instantiationService.invokeFunction(resolveQueryFilePath, path.join('${env:TEST_PATH}', 'test.sql'));
|
const resolvedPath = await instantiationService.invokeFunction(resolveQueryFilePath, path.join('${env:TEST_PATH}', 'test.sql'));
|
||||||
equal(resolvedPath, queryFilePath);
|
ok(isEqual(resolvedPath, URI.file(queryFilePath)));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('resolveQueryFilePath throws if invalid param var specified', async () => {
|
test('resolveQueryFilePath throws if invalid param var specified', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user