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

vscode-mock-debug sends StackFrame#column: 0 response although the debug client sends columnsStartAt1: true for initialize #85

Open
kittaakos opened this issue Jan 18, 2023 · 0 comments

Comments

@kittaakos
Copy link

Hi There,

This is more like a question, but I could not get my head around whether vscode-mock-debug violates the DAP constraints or not. Please help to figure out if this sample adapter implementation behaves correctly.

When I start the Debug readme.md launch configuration on the sampleWorkspace as described in the docs, I can see that the debugger will send the following response for the 'stackTrace' request back to the client:

{
    "seq": 0,
    "type": "response",
    "request_seq": 10,
    "command": "stackTrace",
    "success": true,
    "body": {
        "stackFrames": [
            {
                "id": 0,
                "source": {
                    "name": "readme.md",
                    "path": "/Users/a.kitta/dev/git/vscode-mock-debug/sampleWorkspace/readme.md",
                    "sourceReference": 0,
                    "adapterData": "mock-adapter-data"
                },
                "line": 1,
                "column": 0,
                "name": "VS(0)"
            }
        ],
        "totalFrames": 5
    }
}

StackFrame#column from the specs:

Start position of the range covered by the stack frame. It is measured in UTF-16 code units and the client capability columnsStartAt1 determines whether it is 0- or 1-based. If attribute source is missing or doesn't exist, column is 0 and should be ignored by the client.

Since my debug client is initialized with linesStartAt1: true and columnsStartAt1: true, I would expect that the debugger won't send 0 if the source is available.

This is not a problem in VS Code because the range to reveal is adjusted based on the backing ITextModel before dispatching the revealRange API call. 0 will be mapped to 1. So there are no errors if "stopOnEntry": true is in the lunach.json and the debugger starts and stops at the entry point.

But there are other implementations. For example, in Eclipse Theia, the client knows that the debug sessions are initialized with linesStartAt1: true and columnsStartAt1: true and will expect 1-based line and column values as defined in the specs. Theia will map the position of the StackFrame to an LSP (0-based) position, then when revealing the range in the monaco editor, Theia will convert the 0-based LSP position to a 1-based monaco position. Unfortunately, it does not work reliably as the vscode-mock-debug unexpectedly sends column: 0 although columnsStartAt1: true.

One can argue that it's the client's responsibility to map the Position of the stack frame to the appropriate one, and I have tried to "repair" the position based on the ITextModel, but it does not work. For example, a { line: 0, character: -1 } is not a valid Position in the LSP word, as the properties must be unsigned integers.

Question:
Is the vscode-mock-debugger DAP compliant when it's using the default col: number = 0 0 value for the column when creating the StackFrame instance here:

const sf: DebugProtocol.StackFrame = new StackFrame(f.index, f.name, this.createSource(f.file), this.convertDebuggerLineToClient(f.line));

Thank you!

kittaakos pushed a commit to kittaakos/theia that referenced this issue Jan 18, 2023
paul-marechal added a commit to eclipse-theia/theia that referenced this issue Jan 24, 2023
* fix: various debug fixes and VS Code compatibility enhancements

 - feat: added support for `debug/toolbar` and `debug/variables/context`,
 - feat: added support for `debugState` when context (#11871),
 - feat: can customize debug session timeout, and error handling (#11879),
 - fix: the `debugType` context that is not updated,
 - fix: `configure` must happen after receiving capabilities (#11886),
 - fix: added missing conext menu in the _Variables_ view,
 - fix: handle `setFunctionBreakboints` response with no `body` (#11885),
 - fix: `DebugExt` fires `didStart` event on `didCreate` (#11916),
 - fix: validate editor selection based on the text model (#11880)

Signed-off-by: Akos Kitta <[email protected]>

* fix: use when context for command node filtering

Signed-off-by: Akos Kitta <[email protected]>

* chore: removed test debug VSIX

Signed-off-by: Akos Kitta <[email protected]>

* fix: revert `timeout` check

Signed-off-by: Akos Kitta <[email protected]>

* fix: clarification on the possible `'debugState'`

Signed-off-by: Akos Kitta <[email protected]>

* fix: use hard-coded debugger `clientID` and `clientName`

Signed-off-by: Akos Kitta <[email protected]>

* fix: use review-requested method name

Signed-off-by: Akos Kitta <[email protected]>

* fix: changed method name + added doc

Signed-off-by: Akos Kitta <[email protected]>

* fix: `stopTimeout` is a default `ctor` argument

Signed-off-by: Akos Kitta <[email protected]>

* fix: incorrect method name

Signed-off-by: Akos Kitta <[email protected]>

* fix: both `didCreate` and `didStart` must be API

Signed-off-by: Akos Kitta <[email protected]>

* fix: call both on create and start

Signed-off-by: Akos Kitta <[email protected]>

* fix: workaround for microsoft/vscode-mock-debug#85

Signed-off-by: Akos Kitta <[email protected]>

* simplify writing

The collection of contributed commands was written in a convoluted way,
this commit makes it more straightforward with just 2 loops.

* use `Math.max` to clamp values into positives

The ternary implementation is stricly equivalent to the `Math.max`
function, so use that instead.

* fix default option value handling

Assigning a default option object to set default values is problematic
as said default values will be discarded if any option object is passed.

Instead default values must be handled in conjuction of whatever options
are passed to functions.

Signed-off-by: Akos Kitta <[email protected]>
Co-authored-by: Paul Maréchal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant