Skip to content

Commit fde49b6

Browse files
authored
some enhanced debug utils for the extension (#861)
1 parent 94a2dfc commit fde49b6

File tree

8 files changed

+422
-44
lines changed

8 files changed

+422
-44
lines changed

analysis/src/Cli.ml

+36-13
Original file line numberDiff line numberDiff line change
@@ -85,48 +85,71 @@ Options:
8585
|}
8686

8787
let main () =
88-
match Array.to_list Sys.argv with
88+
let args = Array.to_list Sys.argv in
89+
let debugLevel, args =
90+
match args with
91+
| _ :: "debug-dump" :: logLevel :: rest ->
92+
( (match logLevel with
93+
| "verbose" -> Debug.Verbose
94+
| "regular" -> Regular
95+
| _ -> Off),
96+
"dummy" :: rest )
97+
| args -> (Off, args)
98+
in
99+
Debug.debugLevel := debugLevel;
100+
let debug = debugLevel <> Debug.Off in
101+
let printHeaderInfo path line col =
102+
if debug then
103+
Printf.printf "Debug level: %s\n%s:%s-%s\n\n"
104+
(match debugLevel with
105+
| Debug.Verbose -> "verbose"
106+
| Regular -> "regular"
107+
| Off -> "off")
108+
path line col
109+
in
110+
match args with
89111
| [_; "completion"; path; line; col; currentFile; supportsSnippets] ->
112+
printHeaderInfo path line col;
90113
(Cfg.supportsSnippets :=
91114
match supportsSnippets with
92115
| "true" -> true
93116
| _ -> false);
94-
Commands.completion ~debug:false ~path
117+
Commands.completion ~debug ~path
95118
~pos:(int_of_string line, int_of_string col)
96119
~currentFile
97120
| [_; "definition"; path; line; col] ->
98121
Commands.definition ~path
99122
~pos:(int_of_string line, int_of_string col)
100-
~debug:false
123+
~debug
101124
| [_; "typeDefinition"; path; line; col] ->
102125
Commands.typeDefinition ~path
103126
~pos:(int_of_string line, int_of_string col)
104-
~debug:false
127+
~debug
105128
| [_; "documentSymbol"; path] -> DocumentSymbol.command ~path
106129
| [_; "hover"; path; line; col; currentFile; supportsMarkdownLinks] ->
107130
Commands.hover ~path
108131
~pos:(int_of_string line, int_of_string col)
109-
~currentFile ~debug:false
132+
~currentFile ~debug
110133
~supportsMarkdownLinks:
111134
(match supportsMarkdownLinks with
112135
| "true" -> true
113136
| _ -> false)
114137
| [_; "signatureHelp"; path; line; col; currentFile] ->
115138
Commands.signatureHelp ~path
116139
~pos:(int_of_string line, int_of_string col)
117-
~currentFile ~debug:false
140+
~currentFile ~debug
118141
| [_; "inlayHint"; path; line_start; line_end; maxLength] ->
119142
Commands.inlayhint ~path
120143
~pos:(int_of_string line_start, int_of_string line_end)
121-
~maxLength ~debug:false
122-
| [_; "codeLens"; path] -> Commands.codeLens ~path ~debug:false
123-
| [_; "extractDocs"; path] -> DocExtraction.extractDocs ~path ~debug:false
144+
~maxLength ~debug
145+
| [_; "codeLens"; path] -> Commands.codeLens ~path ~debug
146+
| [_; "extractDocs"; path] -> DocExtraction.extractDocs ~path ~debug
124147
| [_; "codeAction"; path; startLine; startCol; endLine; endCol; currentFile]
125148
->
126149
Commands.codeAction ~path
127150
~startPos:(int_of_string startLine, int_of_string startCol)
128151
~endPos:(int_of_string endLine, int_of_string endCol)
129-
~currentFile ~debug:false
152+
~currentFile ~debug
130153
| [_; "codemod"; path; line; col; typ; hint] ->
131154
let typ =
132155
match typ with
@@ -136,7 +159,7 @@ let main () =
136159
let res =
137160
Codemod.transform ~path
138161
~pos:(int_of_string line, int_of_string col)
139-
~debug:false ~typ ~hint
162+
~debug ~typ ~hint
140163
|> Json.escape
141164
in
142165
Printf.printf "\"%s\"" res
@@ -151,11 +174,11 @@ let main () =
151174
| [_; "references"; path; line; col] ->
152175
Commands.references ~path
153176
~pos:(int_of_string line, int_of_string col)
154-
~debug:false
177+
~debug
155178
| [_; "rename"; path; line; col; newName] ->
156179
Commands.rename ~path
157180
~pos:(int_of_string line, int_of_string col)
158-
~newName ~debug:false
181+
~newName ~debug
159182
| [_; "semanticTokens"; currentFile] ->
160183
SemanticTokens.semanticTokens ~currentFile
161184
| [_; "createInterface"; path; cmiFile] ->

analysis/src/Debug.ml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type debugLevel = Off | Regular | Verbose
2+
3+
let debugLevel = ref Off
4+
5+
let log s =
6+
match !debugLevel with
7+
| Regular | Verbose -> print_endline s
8+
| Off -> ()
9+
10+
let logVerbose s = if !debugLevel = Verbose then print_endline s

client/src/commands.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
export { createInterface } from "./commands/create_interface";
99
export { openCompiled } from "./commands/open_compiled";
1010
export { switchImplIntf } from "./commands/switch_impl_intf";
11+
export { dumpDebug, dumpDebugRetrigger } from "./commands/dump_debug";
1112

1213
export const codeAnalysisWithReanalyze = (
1314
targetDir: string | null,

client/src/commands/code_analysis.ts

+1-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as cp from "child_process";
2-
import * as fs from "fs";
32
import * as path from "path";
43
import {
54
window,
@@ -14,6 +13,7 @@ import {
1413
WorkspaceEdit,
1514
OutputChannel,
1615
} from "vscode";
16+
import { analysisProdPath, getAnalysisBinaryPath } from "../utils";
1717

1818
export type DiagnosticsResultCodeActionsMap = Map<
1919
string,
@@ -127,36 +127,6 @@ let resultsToDiagnostics = (
127127
};
128128
};
129129

130-
let platformDir = process.arch === "arm64" ? process.platform + process.arch : process.platform;
131-
132-
let analysisDevPath = path.join(
133-
path.dirname(__dirname),
134-
"..",
135-
"..",
136-
"analysis",
137-
"rescript-editor-analysis.exe"
138-
);
139-
140-
let analysisProdPath = path.join(
141-
path.dirname(__dirname),
142-
"..",
143-
"..",
144-
"server",
145-
"analysis_binaries",
146-
platformDir,
147-
"rescript-editor-analysis.exe"
148-
);
149-
150-
let getAnalysisBinaryPath = (): string | null => {
151-
if (fs.existsSync(analysisDevPath)) {
152-
return analysisDevPath;
153-
} else if (fs.existsSync(analysisProdPath)) {
154-
return analysisProdPath;
155-
} else {
156-
return null;
157-
}
158-
};
159-
160130
export const runCodeAnalysisWithReanalyze = (
161131
targetDir: string | null,
162132
diagnosticsCollection: DiagnosticCollection,

0 commit comments

Comments
 (0)