Skip to content

Commit 3e77625

Browse files
author
Anup Kamath
committed
enable debugging
1 parent f1d3212 commit 3e77625

File tree

5 files changed

+78
-23
lines changed

5 files changed

+78
-23
lines changed

images/extension-icon.png

10.6 KB
Loading

package.json

+30-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"name": "pgsql",
3-
"displayName": "pgsql",
4-
"version": "1.2.1",
5-
"description": "Develop PGSQL everywhere",
6-
"publisher": "ms-pgsql",
7-
"preview": false,
2+
"name": "vscode-pgsql",
3+
"displayName": "vscode-pgsql",
4+
"version": "0.0.1",
5+
"description": "Develop PostgreSQL everywhere",
6+
"publisher": "Microsoft",
7+
"preview": true,
88
"license": "",
99
"aiKey": "AIF-5574968e-856d-40d2-af67-c89a14e76412",
10-
"icon": "",
10+
"icon": "images/extension-icon.png",
1111
"galleryBanner": {
1212
"color": "#2F2F2F",
1313
"theme": "dark"
@@ -231,6 +231,29 @@
231231
"description": "%pgsql.logDebugInfo%",
232232
"scope": "window"
233233
},
234+
"pgsql.debugSourcePath": {
235+
"type": [
236+
"string",
237+
"null"
238+
],
239+
"default": null,
240+
"description": "[Optional] Path to the source directory of the PostgreSQL Tools Service, for debugging"
241+
},
242+
"pgsql.useDebugSource": {
243+
"type": "boolean",
244+
"default": false,
245+
"description": "[Optional] Enable running the PGSQL extension via the path set in pgsql.debugSourcePath"
246+
},
247+
"pgsql.enableStartupDebugging": {
248+
"type": "boolean",
249+
"default": false,
250+
"description": "[Optional] Whether to make the PostgreSQL Tools Service wait for a debugger to attach when starting"
251+
},
252+
"pgsql.debugServerPort": {
253+
"type": "number",
254+
"default": 3000,
255+
"description": "[Optional] The port to run the PostgreSQL Tools Service remote debugger on (default 3000)"
256+
},
234257
"pgsql.maxRecentConnections": {
235258
"type": "number",
236259
"default": 5,

src/languageservice/serviceclient.ts

+44-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* ------------------------------------------------------------------------------------------ */
55
'use strict';
66

7+
import * as path from 'path';
8+
import * as os from 'os';
9+
710
import { ExtensionContext, workspace, window, OutputChannel, languages } from 'vscode';
811
import { LanguageClient, LanguageClientOptions, ServerOptions,
912
TransportKind, RequestType, NotificationType, NotificationHandler,
@@ -313,21 +316,36 @@ export default class SqlToolsServiceClient {
313316
private createServerOptions(servicePath): ServerOptions {
314317
let serverArgs = [];
315318
let serverCommand: string = servicePath;
316-
if (servicePath.endsWith('.dll')) {
317-
serverArgs = [servicePath];
318-
serverCommand = 'dotnet';
319-
}
320319

321-
// Get the extenion's configuration
322320
let config = workspace.getConfiguration(Constants.extensionConfigSectionName);
321+
323322
if (config) {
323+
// Override the server path with the local debug path if enabled
324+
325+
let useLocalSource = config['useDebugSource'];
326+
if (useLocalSource) {
327+
let localSourcePath = config['debugSourcePath'];
328+
let filePath = path.join(localSourcePath, 'pgsqltoolsservice/pgtoolsservice_main.py');
329+
process.env.PYTHONPATH = localSourcePath;
330+
serverCommand = process.platform === 'win32' ? 'python' : 'python3';
331+
332+
let enableStartupDebugging = config['enableStartupDebugging'];
333+
let debuggingArg = enableStartupDebugging ? '--enable-remote-debugging-wait' : '--enable-remote-debugging';
334+
let debugPort = config['debugServerPort'];
335+
debuggingArg += '=' + debugPort;
336+
serverArgs = [filePath, debuggingArg];
337+
}
338+
339+
let logFileLocation = path.join(this.getDefaultLogLocation(), 'pgsql');
340+
341+
serverArgs.push('--log-dir=' + logFileLocation);
342+
serverArgs.push(logFileLocation);
343+
324344
// Enable diagnostic logging in the service if it is configured
325-
let logDebugInfo = config[Constants.configLogDebugInfo];
345+
let logDebugInfo = config['logDebugInfo'];
326346
if (logDebugInfo) {
327347
serverArgs.push('--enable-logging');
328348
}
329-
330-
// Send Locale for sqltoolsservice localization
331349
let applyLocalization = config[Constants.configApplyLocalization];
332350
if (applyLocalization) {
333351
let locale = vscode.env.language;
@@ -336,10 +354,8 @@ export default class SqlToolsServiceClient {
336354
}
337355
}
338356

339-
340-
// run the service host using dotnet.exe from the path
341-
let serverOptions: ServerOptions = { command: serverCommand, args: serverArgs, transport: TransportKind.stdio };
342-
return serverOptions;
357+
// run the service host
358+
return { command: serverCommand, args: serverArgs, transport: TransportKind.stdio };
343359
}
344360

345361
/**
@@ -384,4 +400,20 @@ export default class SqlToolsServiceClient {
384400
});
385401
});
386402
}
403+
404+
// The function is a duplicate of \src\paths.js. IT would be better to import path.js but it doesn't
405+
// work for now because the extension is running in different process.
406+
private getAppDataPath(): string {
407+
let platform = process.platform;
408+
switch (platform) {
409+
case 'win32': return process.env['APPDATA'] || path.join(process.env['USERPROFILE'], 'AppData', 'Roaming');
410+
case 'darwin': return path.join(os.homedir(), 'Library', 'Application Support');
411+
case 'linux': return process.env['XDG_CONFIG_HOME'] || path.join(os.homedir(), '.config');
412+
default: throw new Error('Platform not supported');
413+
}
414+
}
415+
416+
private getDefaultLogLocation(): string {
417+
return path.join(this.getAppDataPath(), 'code');
418+
}
387419
}

test/initialization.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function ensureExtensionIsActive(): Promise<any> {
1313
}
1414

1515
function waitForExtensionToBeActive(resolve): void {
16-
if (typeof(vscode.extensions.getExtension('ms-pgsql.pgsql')) === 'undefined' ||
17-
!vscode.extensions.getExtension('ms-pgsql.pgsql').isActive) {
16+
if (typeof(vscode.extensions.getExtension('Microsoft.vscode-pgsql')) === 'undefined' ||
17+
!vscode.extensions.getExtension('Microsoft.vscode-pgsql').isActive) {
1818
setTimeout(waitForExtensionToBeActive.bind(this, resolve), 50);
1919
} else {
2020
resolve();

test/telemetry.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Telemetry from '../src/models/telemetry';
55
suite('Telemetry Tests', () => {
66
test('Correct version of applicationInsights is installed', () => {
77
// Find the path of our extension
8-
let ext = vscode.extensions.getExtension('ms-pgsql.pgsql');
8+
let ext = vscode.extensions.getExtension('Microsoft.vscode-pgsql');
99

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

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

0 commit comments

Comments
 (0)