Skip to content

Commit

Permalink
DevTools <-> VSCode integration (#188)
Browse files Browse the repository at this point in the history
Co-authored-by: Jerel Miller <[email protected]>
  • Loading branch information
phryneas and jerelmiller authored Dec 11, 2024
1 parent 6295414 commit 595784f
Show file tree
Hide file tree
Showing 13 changed files with 575 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-bears-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-apollo": minor
---

Adds experimental integration of the Apollo Client DevTools
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ vscode-apollo-*.vsix
# files generated from tests
__tmp__*
.vscode-test
.yalc
yalc.lock
3 changes: 3 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ sampleWorkspace
renovate.json
images/**/*.gif
images/marketplace
.yalc
yalc.lock
start-ac.mjs
16 changes: 16 additions & 0 deletions images/apollo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 42 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 52 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"dependencies": {
"@apollo/client": "3.12.2",
"@apollo/client-devtools-vscode": "^4.19.0",
"@apollo/subgraph": "2.9.1",
"@graphql-tools/schema": "10.0.6",
"@wry/equality": "0.5.7",
Expand All @@ -62,6 +63,7 @@
"vscode-languageserver-textdocument": "1.0.12",
"vscode-uri": "3.0.8",
"which": "4.0.0",
"ws": "8.18.0",
"zod": "3.23.8",
"zod-validation-error": "3.4.0"
},
Expand Down Expand Up @@ -138,6 +140,23 @@
"default": true,
"markdownDescription": "Show a \"Run in Studio\" button to the right of Operation Signatures.",
"scope": "window"
},
"apollographql.devTools.showPanel": {
"type": "string",
"enum": [
"always",
"never",
"detect"
],
"default": "never",
"markdownDescription": "[Experimental Feature] If the Apollo Client DevTools panel should be shown. If set to `detect`, the panel will only be shown if a configuration file with a client project is found in the workspace.",
"scope": "window"
},
"apollographql.devTools.serverPort": {
"type": "number",
"default": 7095,
"markdownDescription": "The Apollo Client DevTools server port. The server will be started as soon as you start using the DevTools panels.",
"scope": "window"
}
}
},
Expand Down Expand Up @@ -279,8 +298,40 @@
"command": "apollographql/showStats",
"title": "Show Status",
"category": "Apollo"
},
{
"command": "apollographql/startDevToolsServer",
"title": "Start Apollo Client DevTools Server",
"category": "Apollo",
"when": "config.apollographql.devTools.showPanel=='always' || (config.apollographql.devTools.showPanel=='detect' && vscode-apollo.hasClientProject)"
},
{
"command": "apollographql/stopDevToolsServer",
"title": "Stop Apollo Client DevTools Server",
"category": "Apollo",
"when": "config.apollographql.devTools.showPanel=='always' || (config.apollographql.devTools.showPanel=='detect' && vscode-apollo.hasClientProject)"
}
]
],
"viewsContainers": {
"panel": [
{
"id": "client-devtools",
"title": "Apollo Client DevTools",
"icon": "images/apollo.svg"
}
]
},
"views": {
"client-devtools": [
{
"type": "webview",
"id": "vscode-apollo-client-devtools",
"name": "Apollo Client DevTools",
"icon": "images/apollo.svg",
"when": "config.apollographql.devTools.showPanel=='always' || (config.apollographql.devTools.showPanel=='detect' && vscode-apollo.hasClientProject)"
}
]
}
},
"galleryBanner": {
"color": "#1d127d",
Expand Down
5 changes: 4 additions & 1 deletion sampleWorkspace/sampleWorkspace.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"path": "../src/language-server/__tests__/fixtures/documents"
}
],
"settings": {}
"settings": {
"apollographql.devTools.showPanel": "detect",
"apollographql.devTools.serverPort": 7095
}
}
4 changes: 4 additions & 0 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ async function main() {
entryPoints: [
"src/extension.ts",
"src/language-server/server.ts",
{
in: require.resolve("@apollo/client-devtools-vscode/panel"),
out: "panel",
},
"src/language-server/config/config.ts",
"src/language-server/config/cache-busting-resolver.js",
],
Expand Down
39 changes: 39 additions & 0 deletions src/debug.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { OutputChannel } from "vscode";
import { TraceValues } from "vscode-languageclient";
import { format } from "node:util";

/**
* for errors (and other logs in debug mode) we want to print
Expand All @@ -21,6 +23,21 @@ export class Debug {
this.outputConsole = outputConsole;
}

private static _traceLevel: Exclude<TraceValues, "compact"> = "off";
public static get traceLevel(): TraceValues {
return Debug._traceLevel;
}
public static set traceLevel(value: TraceValues | undefined) {
console.log("setting trace level to", value);
if (value === "compact") {
// we do not handle "compact" and it's not possible to set in settings, but it doesn't hurt to at least map
// it to another value
this._traceLevel = "messages";
} else {
this._traceLevel = value || "off";
}
}

/**
* Displays an info message prefixed with [INFO]
*/
Expand Down Expand Up @@ -55,6 +72,28 @@ export class Debug {
this.outputConsole.appendLine(`[WARN] ${message}`);
}

public static traceMessage(
short: string,
verbose = short,
...verboseParams: any[]
) {
if (!this.outputConsole) return;
if (Debug.traceLevel === "verbose") {
this.outputConsole.appendLine(
`[Trace] ${format(verbose, ...verboseParams)}`,
);
} else if (Debug.traceLevel === "messages") {
this.outputConsole.appendLine(`[Trace] ${short}`);
}
}

public static traceVerbose(message: string, ...params: any[]) {
if (!this.outputConsole) return;
if (Debug.traceLevel === "verbose") {
this.outputConsole.appendLine(`[Trace] ${format(message, ...params)}`);
}
}

/**
* TODO: enable error reporting and telemetry
*/
Expand Down
Loading

0 comments on commit 595784f

Please sign in to comment.