Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goplus debug support #49

Merged
merged 30 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
239823f
Modify the language id
tsingbx Dec 31, 2023
f0b4bcc
change default debug adapter
tsingbx Dec 31, 2023
8dc2729
language id
tsingbx Dec 31, 2023
ead25e6
chage goDebugFactory and version
tsingbx Jan 1, 2024
2aee4fb
add .gop support, not only .go
tsingbx Jan 1, 2024
03ba373
fix compile error
tsingbx Jan 1, 2024
8430ef5
fix lint errors
tsingbx Jan 1, 2024
9a557b7
fix mac os build error
tsingbx Jan 1, 2024
0974e06
empty
tsingbx Jan 1, 2024
632b6e5
fix .gop
tsingbx Jan 1, 2024
2cd9fb2
skip some test
tsingbx Jan 1, 2024
d870214
change version
tsingbx Jan 1, 2024
9a0564d
Merge branch 'debug' of https://github.com/tsingbx/vscode-gop into debug
tsingbx Jan 1, 2024
51f97e8
undo skip test
tsingbx Jan 1, 2024
75f9136
undo skip test
tsingbx Jan 1, 2024
e3043fc
change version
tsingbx Jan 1, 2024
56aeefa
check all languageId condition again
tsingbx Jan 1, 2024
4e48ee8
add substitutePath
tsingbx Jan 10, 2024
c619af4
only apply substitute rule for .gop file
tsingbx Jan 10, 2024
376820c
undo
tsingbx Jan 11, 2024
909421d
change dlv to gopdlv
tsingbx Jan 11, 2024
3c77965
fix gopdlv install fail
tsingbx Jan 12, 2024
90c8854
support run test debug
tsingbx Jan 12, 2024
9e54d85
change desc from dlv to gopdlv
tsingbx Jan 13, 2024
7a158b6
fix when debut multi tests will wait forever
tsingbx Jan 13, 2024
7b5b3b5
undo add Debug Test At Cursor
tsingbx Jan 24, 2024
eaa2e9d
fix lint error
tsingbx Feb 2, 2024
8006085
update @vscode/test-electron version
tsingbx Feb 6, 2024
3335086
change tip
tsingbx Feb 7, 2024
4d957e0
change reject message
tsingbx Feb 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
412 changes: 142 additions & 270 deletions package-lock.json

Large diffs are not rendered by default.

57 changes: 31 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gop",
"displayName": "Go+ (beta)",
"version": "0.8.1-dev",
"version": "0.8.2-dev",
"preview": false,
"publisher": "goplus",
"description": "Rich Go/Go+ language support for Visual Studio Code",
Expand Down Expand Up @@ -57,6 +57,7 @@
"glob": "7.1.7",
"json-rpc2": "2.0.0",
"moment": "2.29.4",
"package": "^1.0.1",
"semver": "7.3.4",
"tree-kill": "file:third_party/tree-kill",
"vscode-debugadapter": "1.45.0",
Expand All @@ -76,7 +77,7 @@
"@types/sinon": "9.0.11",
"@types/vscode": "1.67.0",
"@vscode/debugadapter-testsupport": "1.58.0",
"@vscode/test-electron": "2.2.0",
"@vscode/test-electron": "2.3.8",
"@vscode/vsce": "2.19.0",
"adm-zip": "0.4.16",
"esbuild": "0.17.10",
Expand Down Expand Up @@ -104,6 +105,7 @@
"workspaceContains:**/*.rdx",
"onDebugInitialConfigurations",
"onDebugResolve:go",
"onDebugResolve:gop",
"onWebviewPanel:welcomeGo"
],
"main": "./dist/goMain.js",
Expand All @@ -125,7 +127,7 @@
"contributes": {
"languages": [
{
"id": "go",
"id":"go",
"extensions": [
".go"
],
Expand Down Expand Up @@ -608,52 +610,55 @@
}
],
"breakpoints": [
{
"language": "gop"
},
{
"language": "go"
}
],
"debuggers": [
{
"type": "go",
"label": "Go",
"type": "gop",
"label": "Go+",
"program": "./dist/debugAdapter.js",
"runtime": "node",
"languages": [
"go"
"gop", "go"
],
"variables": {
"pickProcess": "go.debug.pickProcess",
"pickGoProcess": "go.debug.pickGoProcess"
"pickProcess": "gop.debug.pickProcess",
"pickGoProcess": "gop.debug.pickGoProcess"
},
"configurationSnippets": [
{
"label": "Go: Launch package",
"label": "Go+: Launch package",
"description": "Debug/test the package in the program attribute",
"body": {
"name": "${2:Launch Package}",
"type": "go",
"type": "gop",
"request": "launch",
"mode": "auto",
"program": "^\"\\${fileDirname}${1:}\""
}
},
{
"label": "Go: Launch file",
"label": "Go+: Launch file",
"description": "Debug the file in the program attribute",
"body": {
"name": "${2:Launch file}",
"type": "go",
"type": "gop",
"request": "launch",
"mode": "debug",
"program": "^\"${1:\\${file\\}}\""
}
},
{
"label": "Go: Launch test function",
"label": "Go+: Launch test function",
"description": "Debug the test function in the args, ensure program attributes points to right package",
"body": {
"name": "${3:Launch test function}",
"type": "go",
"type": "gop",
"request": "launch",
"mode": "test",
"program": "^\"\\${workspaceFolder}${1:}\"",
Expand All @@ -664,22 +669,22 @@
}
},
{
"label": "Go: Attach to local process",
"label": "Go+: Attach to local process",
"description": "Attach to an existing process by process ID",
"body": {
"name": "${1:Attach to Process}",
"type": "go",
"type": "gop",
"request": "attach",
"mode": "local",
"processId": 0
}
},
{
"label": "Go: Connect to server",
"label": "Go+: Connect to server",
"description": "Connect to a remote headless debug server",
"body": {
"name": "${1:Connect to server}",
"type": "go",
"type": "gop",
"request": "attach",
"mode": "remote",
"remotePath": "^\"\\${workspaceFolder}\"",
Expand Down Expand Up @@ -785,7 +790,7 @@
},
"dlvFlags": {
"type": "array",
"description": "Extra flags for `dlv`. See `dlv help` for the full list of supported. Flags such as `--log-output`, `--log`, `--log-dest`, `--api-version`, `--output`, `--backend` already have corresponding properties in the debug configuration, and flags such as `--listen` and `--headless` are used internally. If they are specified in `dlvFlags`, they may be ignored or cause an error.",
"description": "Extra flags for `gopdlv`. See `gopdlv help` for the full list of supported. Flags such as `--log-output`, `--log`, `--log-dest`, `--api-version`, `--output`, `--backend` already have corresponding properties in the debug configuration, and flags such as `--listen` and `--headless` are used internally. If they are specified in `dlvFlags`, they may be ignored or cause an error.",
"items": {
"type": "string"
},
Expand Down Expand Up @@ -833,7 +838,7 @@
"lldb",
"rr"
],
"description": "Backend used by delve. Maps to `dlv`'s `--backend` flag."
"description": "Backend used by delve. Maps to `gopdlv`'s `--backend` flag."
},
"output": {
"type": "string",
Expand Down Expand Up @@ -986,7 +991,7 @@
},
"dlvFlags": {
"type": "array",
"description": "Extra flags for `dlv`. See `dlv help` for the full list of supported. Flags such as `--log-output`, `--log`, `--log-dest`, `--api-version`, `--output`, `--backend` already have corresponding properties in the debug configuration, and flags such as `--listen` and `--headless` are used internally. If they are specified in `dlvFlags`, they may be ignored or cause an error.",
"description": "Extra flags for `gopdlv`. See `gopdlv help` for the full list of supported. Flags such as `--log-output`, `--log`, `--log-dest`, `--api-version`, `--output`, `--backend` already have corresponding properties in the debug configuration, and flags such as `--listen` and `--headless` are used internally. If they are specified in `dlvFlags`, they may be ignored or cause an error.",
"items": {
"type": "string"
},
Expand Down Expand Up @@ -1059,7 +1064,7 @@
"lldb",
"rr"
],
"description": "Backend used by delve. Maps to `dlv`'s `--backend` flag."
"description": "Backend used by delve. Maps to `gopdlv`'s `--backend` flag."
},
"logOutput": {
"type": "string",
Expand Down Expand Up @@ -2061,7 +2066,7 @@
},
"dlvFlags": {
"type": "array",
"description": "Extra flags for `dlv`. See `dlv help` for the full list of supported. Flags such as `--log-output`, `--log`, `--log-dest`, `--api-version`, `--output`, `--backend` already have corresponding properties in the debug configuration, and flags such as `--listen` and `--headless` are used internally. If they are specified in `dlvFlags`, they may be ignored or cause an error.",
"description": "Extra flags for `gopdlv`. See `gopdlv help` for the full list of supported. Flags such as `--log-output`, `--log`, `--log-dest`, `--api-version`, `--output`, `--backend` already have corresponding properties in the debug configuration, and flags such as `--listen` and `--headless` are used internally. If they are specified in `dlvFlags`, they may be ignored or cause an error.",
"items": {
"type": "string"
},
Expand Down Expand Up @@ -2098,10 +2103,10 @@
"description": "Alternate tools or alternate paths for the same tools used by the Go extension. Provide either absolute path or the name of the binary in GOPATH/bin, GOROOT/bin or PATH. Useful when you want to use wrapper script for the Go tools.",
"scope": "resource",
"properties": {
"go": {
"gop": {
"type": "string",
"default": "go",
"description": "Alternate tool to use instead of the go binary or alternate path to use for the go binary."
"default": "gop",
"description": "Alternate tool to use instead of the gop binary or alternate path to use for the go binary."
},
"gopls": {
"type": "string",
Expand Down
4 changes: 3 additions & 1 deletion src/commands/applyCoverprofile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { fileExists } from '../utils/pathUtils';

export const applyCoverprofile: CommandFactory = () => {
return () => {
if (!vscode.window.activeTextEditor || !vscode.window.activeTextEditor.document.fileName.endsWith('.go')) {
const fileName = vscode.window.activeTextEditor?.document.fileName;
const notSuportFile = !fileName?.endsWith('.go') && !fileName?.endsWith('.gop');
if (!vscode.window.activeTextEditor || notSuportFile) {
vscode.window.showErrorMessage('Cannot apply coverage profile when no Go file is open.');
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/runBuilds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const runBuilds: CommandFactory = (ctx, goCtx) => (
document: vscode.TextDocument,
goConfig: vscode.WorkspaceConfiguration
) => {
if (document.languageId !== 'go') {
if (document.languageId !== 'go' && document.languageId !== 'gop') {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/toggleGCDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const toggleGCDetails: CommandFactory = (ctx, goCtx) => {
return;
}
const doc = vscode.window.activeTextEditor?.document.uri.toString();
if (!doc || !doc.endsWith('.go')) {
if (!doc || !(doc.endsWith('.go') || doc.endsWith('.gop'))) {
vscode.window.showErrorMessage('"Go: Toggle gc details" command cannot run when no Go file is open.');
return;
}
Expand Down
28 changes: 15 additions & 13 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ interface EvalOut {
}

enum GoVariableFlags {
VariableFixMacosCompileError = 0,
VariableEscaped = 1,
VariableShadowed = 2,
VariableConstant = 4,
Expand Down Expand Up @@ -479,13 +480,13 @@ export class Delve {
}
dlvCwd = program;
isProgramDirectory = true;
} else if (mode !== 'exec' && path.extname(program) !== '.go') {
logError(`The program "${program}" must be a valid go file in debug mode`);
return reject('The program attribute must be a directory or .go file in debug mode');
} else if (mode !== 'exec' && path.extname(program) !== '.go' && path.extname(program) !== '.gop') {
logError(`The program "${program}" must be a valid go or gop file in debug mode`);
return reject('The program attribute must be a directory or .go or .gop file in debug mode');
}
} catch (e) {
logError(`The program "${program}" does not exist: ${e}`);
return reject('The program attribute must point to valid directory, .go file or executable.');
return reject('The program attribute must point to valid directory, .go/.gop file or executable.');
}

// read env from disk and merge into env variables
Expand Down Expand Up @@ -527,12 +528,12 @@ export class Delve {
build.push(program);
}

const goExe = getBinPathWithPreferredGopathGoroot('go', []);
const gopExe = getBinPathWithPreferredGopathGoroot('gop', []);
log(`Current working directory: ${dirname}`);
log(`Building: ${goExe} ${build.join(' ')}`);
log(`Building: ${gopExe} ${build.join(' ')}`);

// Use spawnSync to ensure that the binary exists before running it.
const buffer = spawnSync(goExe, build, buildOptions);
const buffer = spawnSync(gopExe, build, buildOptions);
if (buffer.stderr && buffer.stderr.length > 0) {
const str = buffer.stderr.toString();
if (this.onstderr) {
Expand Down Expand Up @@ -607,24 +608,24 @@ export class Delve {

if (!existsSync(launchArgs.dlvToolPath)) {
log(
`Couldn't find dlv at the Go tools path, ${process.env['GOPATH']}${
`Couldn't find gopdlv at the Go tools path, ${process.env['GOPATH']}${
env['GOPATH'] ? ', ' + env['GOPATH'] : ''
} or ${getEnvPath()}`
);
return reject(
'Cannot find Delve debugger. Install from https://github.com/go-delve/delve & ensure it is in your Go tools path, "GOPATH/bin" or "PATH".'
'Cannot find Go/Go+ debugger. Install from https://github.com/goplus/gopdlv & ensure it is in your Go tools path, "GOPATH/bin" or "PATH".'
);
}

const currentGOWorkspace = getCurrentGoWorkspaceFromGOPATH(env['GOPATH'], dirname);
const currentGOPWorkspace = getCurrentGoWorkspaceFromGOPATH(env['GOPATH'], dirname);
if (!launchArgs.packagePathToGoModPathMap) {
launchArgs.packagePathToGoModPathMap = {};
}
dlvArgs.push(mode || 'debug');
if (mode === 'exec' || (mode === 'debug' && !isProgramDirectory)) {
dlvArgs.push(program);
} else if (currentGOWorkspace && !launchArgs.packagePathToGoModPathMap[dirname]) {
dlvArgs.push(dirname.substr(currentGOWorkspace.length + 1));
} else if (currentGOPWorkspace && !launchArgs.packagePathToGoModPathMap[dirname]) {
dlvArgs.push(dirname.substr(currentGOPWorkspace.length + 1));
}
// add user-specified dlv flags first. When duplicate flags are specified,
// dlv doesn't mind but accepts the last flag value.
Expand Down Expand Up @@ -667,7 +668,7 @@ export class Delve {

if (!existsSync(launchArgs.dlvToolPath)) {
return reject(
'Cannot find Delve debugger. Install from https://github.com/go-delve/delve & ensure it is in your Go tools path, "GOPATH/bin" or "PATH".'
'Cannot find Go/Go+ debugger. Install from https://github.com/goplus/gopdlv & ensure it is in your Go tools path, "GOPATH/bin" or "PATH".'
);
}

Expand Down Expand Up @@ -1112,6 +1113,7 @@ export class GoDebugSession extends LoggingDebugSession {
// The filePath may have a different path separator than the localPath
// So, update it to use the same separator for ease in path replacement.
filePath = normalizeSeparators(filePath);
const ext = path.extname(filePath);
let substitutedPath = filePath;
let substituteRule: { from: string; to: string };
this.substitutePath?.forEach((value) => {
Expand Down
2 changes: 1 addition & 1 deletion src/goBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function buildCode(buildWorkspace?: boolean): CommandFactory {
vscode.window.showInformationMessage('No editor is active, cannot find current package to build');
return;
}
if (editor.document.languageId !== 'go') {
if (editor.document.languageId !== 'go' && editor.document.languageId !== 'gop') {
vscode.window.showInformationMessage(
'File in the active editor is not a Go file, cannot find current package to build'
);
Expand Down
2 changes: 1 addition & 1 deletion src/goCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function removeTestStatus(e: vscode.TextDocumentChangeEvent) {

export function notifyIfGeneratedFile(this: void, e: vscode.TextDocumentChangeEvent) {
const ctx: any = this;
if (e.document.isUntitled || e.document.languageId !== 'go') {
if (e.document.isUntitled || (e.document.languageId !== 'go' && e.document.languageId !== 'gop')) {
return;
}
if (
Expand Down
2 changes: 1 addition & 1 deletion src/goCover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export function applyCodeCoverageToAllEditors(coverProfilePath: string, dir?: st

// goxls: shadow main startcol = 0
let col = parseInt(parse[3], 10);
if (col < 1 && !filename.endsWith('.go')) {
if (col < 1 && !(filename.endsWith('.go') || filename.endsWith('.gop'))) {
col = 1;
}
const startLine = parseInt(parse[2], 10);
Expand Down
Loading
Loading