Skip to content

Commit

Permalink
Enable debug in development (#310)
Browse files Browse the repository at this point in the history
* Enable debug for Liberty LS and Jakarta LS in dev environment

* Add instructions for attaching debugger in VSCode
  • Loading branch information
evie-lau committed Dec 5, 2023
1 parent af9fe48 commit e6f1f16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
15 changes: 13 additions & 2 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Ensure you have [Node.js and npm](https://docs.npmjs.com/downloading-and-install
- Navigate to the Extensions activity bar, or use the shortcut `Ctrl`-`Shift`-`X`
- Click the `...` dropdown menu and select `Install from VSIX` and choose the generated `liberty-tools-vscode-xxx.vsix` file

Step 5 downloads the JARs for Liberty Config Language Server and Eclipse LSP4Jakarta that are consumed by the VS Code client.
If you would like a different version of the language servers other than what is available to download, the following instructions explain how to build these JARs locally. Then rerun steps 6 and 7.
> Step 5 downloads the JARs for Liberty Config Language Server and Eclipse LSP4Jakarta that are consumed by the VS Code client.
If you would like a different version of the language servers other than what is available to download, the following instructions explain how to build these JARs locally.

## Language Servers

Expand All @@ -53,6 +53,17 @@ For more information on building Liberty Config Language Server, see the project

For more information on building Eclipse LSP4Jakarta, see the project documentation on [GitHub](https://github.com/eclipse/lsp4jakarta/blob/main/docs/BUILDING.md). Note that there are [prerequisites](https://github.com/eclipse/lsp4jakarta/blob/main/docs/BUILDING.md#prerequisites) to building this project locally.

### Debugging Language Servers
When running the extension with locally built language servers, a debugger can be attached to the language server process.
The debug ports are as follows:

- Liberty-LemminX: `1054`
- Liberty Language Server: `8002`
- Jakarta LS: `8003`


With the `liberty-language-server` project opened in VSCode, run `Debug attach liberty-ls` or `Debug attach liberty-lemminx` to attach the respective debugger to the running extension.

## Localization

### package.json
Expand Down
29 changes: 13 additions & 16 deletions src/util/javaServerStarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import { workspace } from 'vscode';
import { Executable, ExecutableOptions } from 'vscode-languageclient/node';
import { RequirementsData } from './requirements';
import * as glob from 'glob';
import {LIBERTY_LS_JAR} from '../extension'
import {JAKARTA_LS_JAR, LIBERTY_LS_JAR} from '../extension'

// const DEBUG = startedInDebugMode();
const LIBERTY_LS_DEBUG_PORT = 1064;
const DEBUG = startedInDebugMode();
const LIBERTY_LS_DEBUG_PORT = 8002;
const JAKARTA_LS_DEBUG_PORT = 8003;

// Referenced:
// https://github.com/redhat-developer/vscode-microprofile/blob/master/src/languageServer/javaServerStarter.ts
Expand All @@ -42,19 +43,15 @@ export function prepareExecutable(jarName: string, requirements: RequirementsDat
function prepareParams(jarName: string): string[] {
const params: string[] = [];

// TODO: debug doesn't work yet
// if (DEBUG) {
// if (process.env.SUSPEND_SERVER === 'true') {
// params.push(`-agentlib:jdwp=transport=dt_socket,server=y,address=${DEBUG_PORT}`);
// } else {
// params.push(`-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${DEBUG_PORT},quiet=y`);
// }
// }

// uncomment to debug the Liberty Config Language Server
// if (jarName === LIBERTY_LS_JAR) {
// params.push(`-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=${LIBERTY_LS_DEBUG_PORT}`);
// }
// will only add debug args when run in development, not when run as an extension
if (DEBUG) {
if (jarName === LIBERTY_LS_JAR) {
params.push(`-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${LIBERTY_LS_DEBUG_PORT},quiet=y`);
}
else if (jarName === JAKARTA_LS_JAR) {
params.push(`-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${JAKARTA_LS_DEBUG_PORT},quiet=y`);
}
}

const jarHome = path.resolve(__dirname, "../jars");
params.push('-jar');
Expand Down

0 comments on commit e6f1f16

Please sign in to comment.