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

Fix per-file project-loading #109

Merged
merged 2 commits into from
Nov 6, 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
14 changes: 7 additions & 7 deletions src/lsp/superbol_free_lib/command_indent_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ open Common_args

let action { preproc_options = { source_format; config; _ } ; _ } files =
let module Config = (val config) in
let project = Project_config.load_project () in
let indent_config = Some (Cobol_indent.config project.config.indent_config) in
List.to_seq files
|> Seq.map (fun file ->
let contents = Ez_file.V1.EzFile.read_file file in
indent_range_str
~source_format ~filename:file ~contents ~indent_config ~range:None
~dialect:Config.dialect |> Fmt.pr "%s")
|> Seq.map (fun filename ->
let project = Project.for_ ~filename in
let contents = Ez_file.V1.EzFile.read_file filename in
indent_range_str
~source_format ~filename ~contents ~range:None
~indent_config:(Some (Cobol_indent.config project.config.indent_config))
~dialect:Config.dialect |> Fmt.pr "%s")

let cmd =
let files = ref [] in
Expand Down
10 changes: 5 additions & 5 deletions src/lsp/superbol_free_lib/command_indent_range.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ open Cobol_indent
open Common_args

let action
{ preproc_options = { source_format; config; _ }; _ } ~file ~range
{ preproc_options = { source_format; config; _ }; _ } ~filename ~range
=
let module Config = (val config) in
let project = Project_config.load_project () in
let project = Project.for_ ~filename in
let indent_config = Some (Cobol_indent.config project.config.indent_config) in
let contents = Ez_file.V1.EzFile.read_file file in
indent_range_str ~source_format ~filename:file ~contents ~range ~indent_config
let contents = Ez_file.V1.EzFile.read_file filename in
indent_range_str ~source_format ~filename ~contents ~range ~indent_config
~dialect:Config.dialect |> Fmt.pr "%s"

let cmd =
Expand All @@ -50,7 +50,7 @@ let cmd =
let common = common () in
action
common
~file:!file
~filename:!file
~range:(range start_line end_line)
)
~args
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/superbol_free_lib/command_json_vscode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let cmd =
List.iter parse files
| Some file, [] ->
Vscode_json.Main.write_file file
Vscode_json.Manifest.vscode_enc Project.manifest
Vscode_json.Manifest.vscode_enc Vscode_extension.manifest
| Some _, _ ->
Printf.eprintf
"Actions --gen TARGET and parse files are exclusive\n%!";
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/superbol_free_lib/command_lsp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
open Ezcmd.V2

let lsp_config =
Cobol_lsp.config ~project_layout:Project_config.layout
Cobol_lsp.config ~project_layout:Project.layout

let run_lsp () =
match Cobol_lsp.run ~config:lsp_config with
Expand Down
4 changes: 2 additions & 2 deletions src/lsp/superbol_free_lib/command_project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ open EZCMD.TYPES
let config_cmd =
let dirname = ref None in
let action () =
let project = Project_config.load_project ?dirname:!dirname () in
let project = Project.load ?dirname:!dirname () in
Pretty.out "%s@."
(Ez_toml.V1.TOML.string_of_node
(Ezr_toml.toml project.config.toml_handle))
Expand All @@ -44,7 +44,7 @@ let init_cmd =
"project init"
(fun () ->
Superbol_project.save_config @@
Project_config.load_project ?dirname:!dirname ())
Project.load ?dirname:!dirname ())
~args:[
[], Arg.Anon (0, fun s -> dirname := Some s),
EZCMD.info ~docv:"DIR" "Project directory";
Expand Down
283 changes: 44 additions & 239 deletions src/lsp/superbol_free_lib/project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,250 +2,55 @@
(* *)
(* SuperBOL OSS Studio *)
(* *)
(* Copyright (c) 2022-2023 OCamlPro SAS *)
(* *)
(* Copyright (c) 2023 OCamlPro SAS *)
(* *)
(* All rights reserved. *)
(* This source code is licensed under the MIT license found in the *)
(* LICENSE.md file in the root directory of this source tree. *)
(* *)
(* All rights reserved. *)
(* This source code is licensed under the GNU Affero General Public *)
(* License version 3 found in the LICENSE.md file in the root directory *)
(* of this source tree. *)
(* *)
(**************************************************************************)

open Vscode_json
open Manifest

let vscode_engine = "1.64.0"


let marketplace = Manifest.marketplace
"ocamlpro"
~categories: [
"Formatters" ;
"Programming Languages" ;
"Linters" ;
"Snippets" ;
"Other"
]

let package =
Manifest.package
"superbol"
~displayName: "SuperBOL Studio OSS"
~description: "Provides a COBOL mode in VSCode, based on the SuperBOL LSP \
server for COBOL"
~license: "MIT"
~version: "0.1.0"
~repository: {
type_ = Some "git" ;
url = "https://github.com/OCamlPro/superbol-studio-oss"
}
~homepage: "https://get-superbol.com"
~author: {
author_name = "SuperBOL at OCamlPro" ;
author_email = Some "contact@ocamlpro.com"
}
~keywords: [ "cobol" ; "gnucobol" ]
~main: "./_dist/superbol_vscode_platform.bc.js"
~scripts: [
"compile",
"make compile" ;

"release",
"make release" ;
open Ez_file.V1

"package" ,
"vsce package --out superbol-vscode-platform.vsix --yarn" ;
module DIAGS = Cobol_common.Diagnostics

"deploy:vsce" ,
"vsce publish --packagePath superbol-vscode-platform.vsix --yarn" ;

"deploy:ovsx" ,
"ovsx publish --yarn"
]
~dependencies: [
"@vscode/debugadapter", "^1.61.0" ;
"@vscode/debugprotocol", "^1.61.0" ;
"polka" , "^1.0.0-next.22" ;
"sirv" , "^2.0.2" ;
"vscode-languageclient" , "8.0.2"
]
~devDependencies: [
"@types/vscode" , vscode_engine ;
"esbuild" , "0.15.16" ;
"fs-extra" , "10.0.1" ;
"mocha" , "9.2.2" ;
"npm-run-all" , "4.1.5" ;
"ovsx" , "0.1.0-next.97d460c" ;
"prettier" , "^2.5.1" ;
"vsce" , "^2.15.0" ;
"vscode-test" , "1.6.1"
]

let contributes =
Manifest.contributes ()
~languages: [
Manifest.language "cobol"
~aliases: [ "COBOL" ]
~filenamePatterns: [ "*.cbl"; "*.cob" ]
]
~debuggers: [
Manifest.debugger "cobol"
~label:"GnuCOBOL Debugger"
~languages: [ "cobol" ]
~program: "gdb"
(* TODO unsupported ???
"args": [
"--init-eval-command=\"source /usr/local/bin/cobcd.py\""
],
*)
~configurationAttributes:
(Manifest.any
{| {
"launch": {
"type": "cobol",
"required": [
"program"
],
"properties": {
"program": {
"type": "string",
"default": "${workspaceFolder}/a.out"
}
}
}
}
|}
)
~configurationSnippets:
[
Manifest.any
{|
{
"label": "Debug COBOL",
"description": "New COBOL debugging configuration",
"body": {
"type": "cobol",
"request": "launch",
"name": "${2:Launch Program}",
"program": "${workspaceFolder}/${1:Program}"
let layout =
Superbol_project.{
project_config_filename = "superbol.toml";
relative_work_dirname = "_superbol";
}
}
|}
]
]
~breakpoints: [ Manifest.breakpoint "COBOL" ]
~configuration:
( Manifest.configuration ~title:"SuperBOL COBOL"
[
Manifest.PROPERTY.bool
"superbol.globalFormatTakesSelection"
~default:false
~description:
"If something is selected, only format the selection" ;

Manifest.PROPERTY.string "superbol.path"
~default:"superbol-free"
~description:
"Name of the `superbol-free` executable if available in PATH; \
may be an absolute path otherwise."
] )
~taskDefinitions: [
Manifest.taskDefinition
"superbol"
~properties: [
Manifest.PROPERTY.array "copybooks"
~description:"The list of copybooks paths" ;

Manifest.PROPERTY.enum "sourceFormat"
~cases:Cobol_config.DIALECT.all_canonical_names
~description: "The source format of the code"
;

Manifest.PROPERTY.string "dialect"
~description: "The COBOL dialect used" ;

Manifest.PROPERTY.bool "forDebugging"
~description: "Build for debugging" ;

Manifest.PROPERTY.array "extensions"
~description: "Add cobol file extensions"
]
]
~problemPatterns:[
Manifest.problemPattern
(Some "^(.*): ?(\\d+): (error|warning): ([^[]*)(\\[(.*)\\])?$")
~name:"gnucobol"
~file:1
~line:2
~severity:3
~message:4
~code:6;
Manifest.problemPattern
(Some "^(.*):(\\d+):\\s?(warning|Warnung|[wW]aarschuwing|[aA]lerta|avertissement|упозорење)\\s?:([^[]*)(\\[(.*)\\])?$")
~name:"gnucobol-warning"
~file:1
~line:2
~message:4
~code:6;
Manifest.problemPattern
(Some "^(.*): ?(\\d+):\\s?(error|Fehler|[fF]out|[eE]rrores|[eE]rrores|erreur|грешка)\\s?:\\s?([^[]*)(\\[(.*)\\])?$")
~name:"gnucobol-error"
~file:1
~line:2
~message:4
~code:6;
Manifest.problemPattern
(Some "^(.*): ?(\\d+): (note|Anmerkung|[nN]ota): ([^[]*)(\\[(.*)\\])?$")
~name:"gnucobol-note"
~file:1
~line:2
~message:4
~code:6;
]
~problemMatchers:[
Manifest.problemMatcher ()
~name:"gnucobol"
~owner:"cobol"
~fileLocation:["absolute"]
~pattern:[Manifest.ProblemName "$gnucobol"]
~source:"GnuCOBOL";
Manifest.problemMatcher ()
~name:"gnucobol-warning"
~owner:"cobol"
~fileLocation:["absolute"]
~pattern:[Manifest.ProblemName "$gnucobol-warning"]
~severity:"warning"
~source:"GnuCOBOL";
Manifest.problemMatcher ()
~name:"gnucobol-error"
~owner:"cobol"
~fileLocation:["absolute"]
~pattern:[Manifest.ProblemName "$gnucobol-error"]
~severity:"error"
~source:"GnuCOBOL";
Manifest.problemMatcher ()
~name:"gnucobol-note"
~owner:"cobol"
~fileLocation:["absolute"]
~pattern:[Manifest.ProblemName "$gnucobol-note"]
~severity:"info"
~source:"GnuCOBOL";
]
~commands:[
Manifest.command ()
~command:"superbol.server.restart"
~title:"Restart Language Server"
~category:"superbol"
]

let manifest =
Manifest.vscode
package
~marketplace
~engines: ( "^" ^ vscode_engine )
~activationEvents: [
"onLanguage:cobol" ;
"onDebug"
]
~contributes
let try_load ~f arg =
try f arg with
| Superbol_project.Config.ERROR e ->
DIAGS.(pp Fmt.stderr @@ One.error "%a"
Superbol_project.Diagnostics.pp_error e);
exit 2
| Sys_error msg | Invalid_argument msg ->
DIAGS.(pp Fmt.stderr @@ One.error "%s" msg);
exit 2

(* Direct loading (based on directory name) *)

let in_ ~dirname =
Pretty.error "Loading project in `%s'@." dirname;
try_load () ~f:begin fun () ->
let rootdir = Superbol_project.rootdir_at ~dirname in
let project = Superbol_project.for_ ~rootdir ~layout in
DIAGS.show_n_forget project
end

let load ?(dirname = EzFile.current_dir_name) () = in_ ~dirname

(* Indirect loading (based on file name, looking up the directory hierarchy) *)

let for_ ~filename =
Pretty.error "Looking up project for `%s'@." filename;
try_load () ~f:begin fun () ->
let rootdir = Superbol_project.rootdir_for ~filename ~layout in
let project = Superbol_project.for_ ~rootdir ~layout in
DIAGS.show_n_forget project
end

let for_filename filename = for_ ~filename
Loading
Loading