Skip to content

Enhanced debug utils for extension dev #861

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

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 36 additions & 13 deletions analysis/src/Cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,48 +85,71 @@ Options:
|}

let main () =
match Array.to_list Sys.argv with
let args = Array.to_list Sys.argv in
let debugLevel, args =
match args with
| _ :: "debug-dump" :: logLevel :: rest ->
( (match logLevel with
| "verbose" -> Debug.Verbose
| "regular" -> Regular
| _ -> Off),
"dummy" :: rest )
| args -> (Off, args)
in
Debug.debugLevel := debugLevel;
let debug = debugLevel <> Debug.Off in
let printHeaderInfo path line col =
if debug then
Printf.printf "Debug level: %s\n%s:%s-%s\n\n"
(match debugLevel with
| Debug.Verbose -> "verbose"
| Regular -> "regular"
| Off -> "off")
path line col
in
match args with
| [_; "completion"; path; line; col; currentFile; supportsSnippets] ->
printHeaderInfo path line col;
(Cfg.supportsSnippets :=
match supportsSnippets with
| "true" -> true
| _ -> false);
Commands.completion ~debug:false ~path
Commands.completion ~debug ~path
~pos:(int_of_string line, int_of_string col)
~currentFile
| [_; "definition"; path; line; col] ->
Commands.definition ~path
~pos:(int_of_string line, int_of_string col)
~debug:false
~debug
| [_; "typeDefinition"; path; line; col] ->
Commands.typeDefinition ~path
~pos:(int_of_string line, int_of_string col)
~debug:false
~debug
| [_; "documentSymbol"; path] -> DocumentSymbol.command ~path
| [_; "hover"; path; line; col; currentFile; supportsMarkdownLinks] ->
Commands.hover ~path
~pos:(int_of_string line, int_of_string col)
~currentFile ~debug:false
~currentFile ~debug
~supportsMarkdownLinks:
(match supportsMarkdownLinks with
| "true" -> true
| _ -> false)
| [_; "signatureHelp"; path; line; col; currentFile] ->
Commands.signatureHelp ~path
~pos:(int_of_string line, int_of_string col)
~currentFile ~debug:false
~currentFile ~debug
| [_; "inlayHint"; path; line_start; line_end; maxLength] ->
Commands.inlayhint ~path
~pos:(int_of_string line_start, int_of_string line_end)
~maxLength ~debug:false
| [_; "codeLens"; path] -> Commands.codeLens ~path ~debug:false
| [_; "extractDocs"; path] -> DocExtraction.extractDocs ~path ~debug:false
~maxLength ~debug
| [_; "codeLens"; path] -> Commands.codeLens ~path ~debug
| [_; "extractDocs"; path] -> DocExtraction.extractDocs ~path ~debug
| [_; "codeAction"; path; startLine; startCol; endLine; endCol; currentFile]
->
Commands.codeAction ~path
~startPos:(int_of_string startLine, int_of_string startCol)
~endPos:(int_of_string endLine, int_of_string endCol)
~currentFile ~debug:false
~currentFile ~debug
| [_; "codemod"; path; line; col; typ; hint] ->
let typ =
match typ with
Expand All @@ -136,7 +159,7 @@ let main () =
let res =
Codemod.transform ~path
~pos:(int_of_string line, int_of_string col)
~debug:false ~typ ~hint
~debug ~typ ~hint
|> Json.escape
in
Printf.printf "\"%s\"" res
Expand All @@ -151,11 +174,11 @@ let main () =
| [_; "references"; path; line; col] ->
Commands.references ~path
~pos:(int_of_string line, int_of_string col)
~debug:false
~debug
| [_; "rename"; path; line; col; newName] ->
Commands.rename ~path
~pos:(int_of_string line, int_of_string col)
~newName ~debug:false
~newName ~debug
| [_; "semanticTokens"; currentFile] ->
SemanticTokens.semanticTokens ~currentFile
| [_; "createInterface"; path; cmiFile] ->
Expand Down
10 changes: 10 additions & 0 deletions analysis/src/Debug.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type debugLevel = Off | Regular | Verbose

let debugLevel = ref Off

let log s =
match !debugLevel with
| Regular | Verbose -> print_endline s
| Off -> ()

let logVerbose s = if !debugLevel = Verbose then print_endline s
1 change: 1 addition & 0 deletions client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
export { createInterface } from "./commands/create_interface";
export { openCompiled } from "./commands/open_compiled";
export { switchImplIntf } from "./commands/switch_impl_intf";
export { dumpDebug, dumpDebugRetrigger } from "./commands/dump_debug";

export const codeAnalysisWithReanalyze = (
targetDir: string | null,
Expand Down
32 changes: 1 addition & 31 deletions client/src/commands/code_analysis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as cp from "child_process";
import * as fs from "fs";
import * as path from "path";
import {
window,
Expand All @@ -14,6 +13,7 @@ import {
WorkspaceEdit,
OutputChannel,
} from "vscode";
import { analysisProdPath, getAnalysisBinaryPath } from "../utils";

export type DiagnosticsResultCodeActionsMap = Map<
string,
Expand Down Expand Up @@ -127,36 +127,6 @@ let resultsToDiagnostics = (
};
};

let platformDir = process.arch === "arm64" ? process.platform + process.arch : process.platform;

let analysisDevPath = path.join(
path.dirname(__dirname),
"..",
"..",
"analysis",
"rescript-editor-analysis.exe"
);

let analysisProdPath = path.join(
path.dirname(__dirname),
"..",
"..",
"server",
"analysis_binaries",
platformDir,
"rescript-editor-analysis.exe"
);

let getAnalysisBinaryPath = (): string | null => {
if (fs.existsSync(analysisDevPath)) {
return analysisDevPath;
} else if (fs.existsSync(analysisProdPath)) {
return analysisProdPath;
} else {
return null;
}
};

export const runCodeAnalysisWithReanalyze = (
targetDir: string | null,
diagnosticsCollection: DiagnosticCollection,
Expand Down
Loading