Skip to content

Commit

Permalink
enable debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Anup Kamath committed Apr 6, 2018
1 parent f1d3212 commit 3e77625
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 23 deletions.
Binary file added images/extension-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 30 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "pgsql",
"displayName": "pgsql",
"version": "1.2.1",
"description": "Develop PGSQL everywhere",
"publisher": "ms-pgsql",
"preview": false,
"name": "vscode-pgsql",
"displayName": "vscode-pgsql",
"version": "0.0.1",
"description": "Develop PostgreSQL everywhere",
"publisher": "Microsoft",
"preview": true,
"license": "",
"aiKey": "AIF-5574968e-856d-40d2-af67-c89a14e76412",
"icon": "",
"icon": "images/extension-icon.png",
"galleryBanner": {
"color": "#2F2F2F",
"theme": "dark"
Expand Down Expand Up @@ -231,6 +231,29 @@
"description": "%pgsql.logDebugInfo%",
"scope": "window"
},
"pgsql.debugSourcePath": {
"type": [
"string",
"null"
],
"default": null,
"description": "[Optional] Path to the source directory of the PostgreSQL Tools Service, for debugging"
},
"pgsql.useDebugSource": {
"type": "boolean",
"default": false,
"description": "[Optional] Enable running the PGSQL extension via the path set in pgsql.debugSourcePath"
},
"pgsql.enableStartupDebugging": {
"type": "boolean",
"default": false,
"description": "[Optional] Whether to make the PostgreSQL Tools Service wait for a debugger to attach when starting"
},
"pgsql.debugServerPort": {
"type": "number",
"default": 3000,
"description": "[Optional] The port to run the PostgreSQL Tools Service remote debugger on (default 3000)"
},
"pgsql.maxRecentConnections": {
"type": "number",
"default": 5,
Expand Down
56 changes: 44 additions & 12 deletions src/languageservice/serviceclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* ------------------------------------------------------------------------------------------ */
'use strict';

import * as path from 'path';
import * as os from 'os';

import { ExtensionContext, workspace, window, OutputChannel, languages } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions,
TransportKind, RequestType, NotificationType, NotificationHandler,
Expand Down Expand Up @@ -313,21 +316,36 @@ export default class SqlToolsServiceClient {
private createServerOptions(servicePath): ServerOptions {
let serverArgs = [];
let serverCommand: string = servicePath;
if (servicePath.endsWith('.dll')) {
serverArgs = [servicePath];
serverCommand = 'dotnet';
}

// Get the extenion's configuration
let config = workspace.getConfiguration(Constants.extensionConfigSectionName);

if (config) {
// Override the server path with the local debug path if enabled

let useLocalSource = config['useDebugSource'];
if (useLocalSource) {
let localSourcePath = config['debugSourcePath'];
let filePath = path.join(localSourcePath, 'pgsqltoolsservice/pgtoolsservice_main.py');
process.env.PYTHONPATH = localSourcePath;
serverCommand = process.platform === 'win32' ? 'python' : 'python3';

let enableStartupDebugging = config['enableStartupDebugging'];
let debuggingArg = enableStartupDebugging ? '--enable-remote-debugging-wait' : '--enable-remote-debugging';
let debugPort = config['debugServerPort'];
debuggingArg += '=' + debugPort;
serverArgs = [filePath, debuggingArg];
}

let logFileLocation = path.join(this.getDefaultLogLocation(), 'pgsql');

serverArgs.push('--log-dir=' + logFileLocation);
serverArgs.push(logFileLocation);

// Enable diagnostic logging in the service if it is configured
let logDebugInfo = config[Constants.configLogDebugInfo];
let logDebugInfo = config['logDebugInfo'];
if (logDebugInfo) {
serverArgs.push('--enable-logging');
}

// Send Locale for sqltoolsservice localization
let applyLocalization = config[Constants.configApplyLocalization];
if (applyLocalization) {
let locale = vscode.env.language;
Expand All @@ -336,10 +354,8 @@ export default class SqlToolsServiceClient {
}
}


// run the service host using dotnet.exe from the path
let serverOptions: ServerOptions = { command: serverCommand, args: serverArgs, transport: TransportKind.stdio };
return serverOptions;
// run the service host
return { command: serverCommand, args: serverArgs, transport: TransportKind.stdio };
}

/**
Expand Down Expand Up @@ -384,4 +400,20 @@ export default class SqlToolsServiceClient {
});
});
}

// The function is a duplicate of \src\paths.js. IT would be better to import path.js but it doesn't
// work for now because the extension is running in different process.
private getAppDataPath(): string {
let platform = process.platform;
switch (platform) {
case 'win32': return process.env['APPDATA'] || path.join(process.env['USERPROFILE'], 'AppData', 'Roaming');
case 'darwin': return path.join(os.homedir(), 'Library', 'Application Support');
case 'linux': return process.env['XDG_CONFIG_HOME'] || path.join(os.homedir(), '.config');
default: throw new Error('Platform not supported');
}
}

private getDefaultLogLocation(): string {
return path.join(this.getAppDataPath(), 'code');
}
}
4 changes: 2 additions & 2 deletions test/initialization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function ensureExtensionIsActive(): Promise<any> {
}

function waitForExtensionToBeActive(resolve): void {
if (typeof(vscode.extensions.getExtension('ms-pgsql.pgsql')) === 'undefined' ||
!vscode.extensions.getExtension('ms-pgsql.pgsql').isActive) {
if (typeof(vscode.extensions.getExtension('Microsoft.vscode-pgsql')) === 'undefined' ||
!vscode.extensions.getExtension('Microsoft.vscode-pgsql').isActive) {
setTimeout(waitForExtensionToBeActive.bind(this, resolve), 50);
} else {
resolve();
Expand Down
4 changes: 2 additions & 2 deletions test/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Telemetry from '../src/models/telemetry';
suite('Telemetry Tests', () => {
test('Correct version of applicationInsights is installed', () => {
// Find the path of our extension
let ext = vscode.extensions.getExtension('ms-pgsql.pgsql');
let ext = vscode.extensions.getExtension('Microsoft.vscode-pgsql');

// Open the applicationInsights node module package.json
const appInsightsPackage: any = require(
Expand All @@ -29,7 +29,7 @@ suite('Telemetry Tests', () => {
});

test('Path before /out/ is stripped', () => {
let errorString = '/User/myuser/vscode/extensions/ms-pgsql.pgsql-0.1.5/out/src/controller/mainController.js:216.45';
let errorString = '/User/myuser/vscode/extensions/Microsoft.vscode-pgsql-0.0.1/out/src/controller/mainController.js:216.45';
let expectedErrorString = 'src/controller/mainController.js:216.45';
let actualErrorString = Telemetry.FilterErrorPath(errorString);
assert.equal(actualErrorString, expectedErrorString);
Expand Down

0 comments on commit 3e77625

Please sign in to comment.