|
1 | | -# Compiling and Visual Debugging with VSCode |
| 1 | +# Using VSCode with MODFLOW 6 |
2 | 2 |
|
3 | | -VSCode is a free integrated development environment for Windows, Linux, and |
4 | | -MacOS. There are two major advantages over Visual Studio: |
| 3 | +This document describes how to use VSCode to modify, format, build and test MODFLOW 6. VSCode is a free integrated development environment for Windows, Linux, and MacOS. Most of VSCode's source code is open-source and the releases are (proprietary) freeware. |
5 | 4 |
|
6 | | -* Most of VSCode's source code is open-source and the releases are (proprietary) freeware. |
7 | | -* VSCode runs on Linux. |
| 5 | +The folder containing this README markdown file (`.vscode/`) contains the configuration files for using VSCode for MODFLOW 6 development. At the moment they are used for formatting, building, and debugging MODFLOW 6. In order to build MODFLOW 6 follow the steps in [DEVELOPER.md](../DEVELOPER.md) |
8 | 6 |
|
9 | | -This folder contains the configuration files for using VSCode for MODFLOW 6 |
10 | | -development. |
11 | | -At the moment they are used for building and debugging MODFLOW 6. |
12 | | -In order to build MODFLOW 6 follow the steps in [DEVELOPER.md](../DEVELOPER.md) |
| 7 | +<!-- START doctoc generated TOC please keep comment here to allow auto update --> |
| 8 | +<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> |
13 | 9 |
|
14 | | -## Visual Studio Code |
| 10 | +- [Setting up Visual Studio Code](#setting-up-visual-studio-code) |
| 11 | + - [Installation](#installation) |
| 12 | + - [Visual Studio Code Extensions](#visual-studio-code-extensions) |
| 13 | + - [Dependencies](#dependencies) |
| 14 | + - [Running VSCode](#running-vscode) |
| 15 | + - [Final VSCode setup](#final-vscode-setup) |
| 16 | +- [MODFLOW 6 VSCode Tasks](#modflow-6-vscode-tasks) |
| 17 | + - [Compiling](#compiling) |
| 18 | + - [Debugging](#debugging) |
| 19 | + - [Formatting](#formatting) |
| 20 | + - [Additional tasks](#additional-tasks) |
| 21 | + |
| 22 | +<!-- END doctoc generated TOC please keep comment here to allow auto update --> |
| 23 | + |
| 24 | +## Setting up Visual Studio Code |
| 25 | + |
| 26 | +### Installation |
15 | 27 |
|
16 | 28 | Install VSCode from https://code.visualstudio.com/ |
17 | 29 |
|
18 | | -### Extensions |
| 30 | +### Visual Studio Code Extensions |
19 | 31 |
|
20 | 32 | Install the following VSCode extensions: |
21 | 33 |
|
22 | 34 | - Modern Fortran: |
23 | 35 | https://marketplace.visualstudio.com/items?itemName=krvajalm.linter-gfortran |
24 | 36 |
|
25 | | -Note: The Remote - WSL extension may be required if you want to use a windows VSCode |
26 | | -installation in a WSL environment. |
| 37 | +Note: The [Remote - WSL extension](https://code.visualstudio.com/docs/remote/wsl) may be required if you want to use a windows VSCode installation in a WSL environment. |
27 | 38 |
|
28 | 39 | ### Dependencies |
29 | 40 |
|
30 | | -Required and optional dependencies for MODFLOW 6 are discussed in [DEVELOPER.md](../DEVELOPER.md) |
| 41 | +Required and optional dependencies for MODFLOW 6 are discussed in [DEVELOPER.md](../DEVELOPER.md). Required dependencies should be installed prior to setting up VSCode for MODFLOW 6. |
31 | 42 |
|
32 | | -### Settings |
33 | | - |
34 | | -Add [settings.json](https://code.visualstudio.com/docs/getstarted/settings#_settingsjson) to the |
35 | | -`modflow6/.vscode` directory if not already there. The following settings can be considered a |
36 | | -starting place as the contents of this file are dictated both by desired VSCode behavior and |
37 | | -environmental factors: |
| 43 | +### Running VSCode |
38 | 44 |
|
39 | | -In general, to determine the path of an installed tool in your environment run: |
40 | | -- bash: `which <toolname>`, e.g. `which fortls` |
41 | | -- cmd: `where <toolname>`, e.g. `where python` |
42 | | -- PowerShell: `Get-Command <toolname>` e.g. `Get-Command fprettify` |
| 45 | +Open the top level `modflow6` repository directory on your system when starting VSCode. The program will then look for the `modflow6/.vscode` directory to discover settings relevant to your session. |
43 | 46 |
|
44 | | -1. Activate the conda environment: |
| 47 | +A nice alternative on any system is to start VSCode from the shell. For example, in a bash or git bash shell (windows), change to the `modflow6` directory and execute the command: |
45 | 48 |
|
46 | 49 | ```bash |
47 | | -conda activate modflow6 |
| 50 | +code . |
48 | 51 | ``` |
49 | 52 |
|
50 | | -2. Determine the path of `fortls` and `fprettify` |
| 53 | +Note the dot (".") at the end of the command. Starting in this way, VSCode will open as desired, inheriting and discovering expected runtime settings in the correct directory location. |
51 | 54 |
|
52 | | -3. Set the setting "fortran.fortls.path" and "fortran.formatting.path": |
53 | | -```json |
54 | | -{ |
55 | | - "fortran.fortls.path": "/path/to/fortls", |
56 | | - "fortran.formatting.path": "/path/to/fprettify", |
57 | | -} |
58 | | -``` |
| 55 | +### Final VSCode setup |
59 | 56 |
|
60 | | -The fortran formatter can be integrated with VSCode using the following settings: |
| 57 | +A few additional steps are required to finalize the VSCode setup for MODFLOW 6. The remaining steps are: |
61 | 58 |
|
62 | | -```json |
63 | | -{ |
64 | | - "[fortran]": { |
65 | | - "editor.formatOnSave": true, |
66 | | - }, |
67 | | - "fortran.formatting.formatter": "fprettify", |
68 | | - "fortran.formatting.fprettifyArgs": ["-c", "/path/to/modflow6/.fprettify.yaml"], |
69 | | -} |
70 | | -``` |
| 59 | +1. [Select the python interpreter](https://code.visualstudio.com/docs/python/environments#_working-with-python-interpreters) for the MODFLOW 6 workspace. To select the python interpreter run: |
71 | 60 |
|
72 | | -Setting the formatter up in this way will cause a source file to reformat with each explicit save. |
| 61 | + * Press `Ctrl + Shift + P` in VSCode. |
| 62 | + * Type `Python: Select Interpreter`. |
| 63 | + * Select `Run Task` (press Enter). |
| 64 | + * Select the `modflow6` conda environment. |
73 | 65 |
|
74 | | -### Running VSCode |
| 66 | +2. Open a new terminal in VSCode and determine the path to the Fortran language server (`fortls`) and `fprettify` using the syntax for your terminal (`cmd`, `bash`, `powershell`). |
75 | 67 |
|
76 | | -Open the top level `modflow6` repository directory on your system when starting VSCode. The program will |
77 | | -then look for the `modflow6/.vscode` directory to discover settings relevant to your session. |
| 68 | +3. Set the setting "fortran.fortls.path" and "fortran.formatting.path": |
78 | 69 |
|
79 | | -A nice alternative on any system is to start VSCode from the shell. For example, in a bash or git bash |
80 | | -shell (windows), change to the `modflow6` directory and execute the command: |
| 70 | + ```json |
| 71 | + { |
| 72 | + "fortran.fortls.path": "/path/to/fortls", |
| 73 | + "fortran.formatting.path": "/path/to/fprettify", |
| 74 | + } |
| 75 | + ``` |
| 76 | + |
| 77 | +4. The fortran formatter can be integrated with VSCode using the following settings: |
| 78 | + |
| 79 | + ```json |
| 80 | + { |
| 81 | + "[fortran]": { |
| 82 | + "editor.formatOnSave": true, |
| 83 | + }, |
| 84 | + "fortran.formatting.formatter": "fprettify", |
| 85 | + "fortran.formatting.fprettifyArgs": ["-c", "/path/to/modflow6/.fprettify.yaml"], |
| 86 | + } |
| 87 | + ``` |
| 88 | + |
| 89 | + Setting the formatter up in this way will cause a source file to reformat with each explicit save. |
| 90 | + |
| 91 | +In general, to determine the path to python, the fortran language server (`fortls`), and `fprettify` in your environment run: |
| 92 | + |
| 93 | +- bash, zsh: `which <toolname>`, e.g. `which fortls` |
| 94 | +- cmd: `where <toolname>`, e.g. `where python` |
| 95 | +- PowerShell: `Get-Command <toolname>` e.g. `Get-Command fprettify` |
81 | 96 |
|
82 | | -```bash |
83 | | -code . |
84 | | -``` |
| 97 | +## MODFLOW 6 VSCode Tasks |
85 | 98 |
|
86 | | -Note the dot. Starting in this way, VSCode will open as desired, inheriting and discovering |
87 | | -expected runtime settings in the correct directory location. |
| 99 | +A number of MODFLOW 6 development tasks in the [`.vscode/settings.json`](./settings.json) file in the MODFLOW 6 repository. Debugging tasks are included in the `.vscode/launch.json` file, that you will create (instructions below). The tasks includes tasks to compile, debug, and format files. A number of miscellaneous tasks are also included to help prepare required files for Pull Requests (for example, makefiles). |
88 | 100 |
|
89 | 101 | ### Compiling |
90 | 102 |
|
91 | 103 | In order to compile Fortran source run: |
92 | 104 |
|
93 | 105 | * Press `Ctrl + Shift + P` in VSCode. |
94 | | -* Type `Tasks`. |
95 | | -* Select `Run Task` (press Enter). |
| 106 | +* Type `Tasks: Run Build Task` (press Enter). |
96 | 107 | * Select the suitable task for your situation. |
97 | 108 |
|
| 109 | +Tasks are available to build MODFLOW 6 using gfortran and Intel Fortran (ifort). If you have used one of the Rebuild tasks, Build tasks for the same compiler can be used to just recompile modified source files and relink the object files. There are also pixi tasks for MODFLOW 6 build using gfortran. |
| 110 | + |
| 111 | +Available compiling tasks include: |
| 112 | + |
| 113 | +* `Rebuild mf6 (gfortran, release)` |
| 114 | +* `Rebuild mf6 (ifort, release)` |
| 115 | +* `Rebuild mf6 (gfortran, debug)` |
| 116 | +* `Rebuild mf6 (ifort, debug)` |
| 117 | +* `Build mf6 (gfortran, release)` |
| 118 | +* `Build mf6 (ifort, release)` |
| 119 | +* `Build mf6 (gfortran, debug)` |
| 120 | +* `Build mf6 (ifort, debug)` |
| 121 | +* `Pixi - Rebuild mf6 (gfortran, release)` |
| 122 | +* `Pixi - Rebuild mf6 (gfortran, debug)` |
| 123 | +* `Pixi - Build mf6 (gfortran, release)` |
| 124 | +* `Pixi - Build mf6 (gfortran, debug)` |
| 125 | + |
| 126 | + |
98 | 127 | ### Debugging |
99 | 128 |
|
100 | 129 | Add a `launch.json` in `.vscode` similar to this. |
@@ -154,3 +183,39 @@ After building modflow, you can start debugging. |
154 | 183 |
|
155 | 184 | - Set a breakpoint somewhere in the source code. |
156 | 185 | - Press `Ctrl + F5` to start debugging. |
| 186 | + |
| 187 | +### Formatting |
| 188 | + |
| 189 | +There are a number of VSCode tasks to determine if any of the Fortran source files, python code or scripts, LaTeX files, and markdown files in the MODFLOW 6 repository need to be reformatted. |
| 190 | + |
| 191 | +In order format file run: |
| 192 | + |
| 193 | +* Press `Ctrl + Shift + P` in VSCode. |
| 194 | +* Type `Tasks: Run Build Task` (press Enter). |
| 195 | +* Select the suitable task for your situation. |
| 196 | + |
| 197 | +Currently available formatting tasks include: |
| 198 | + |
| 199 | +* `Check spelling` - check spelling in Fortran source files, python code or scripts, LaTeX files, and markdown files |
| 200 | +* `Check Fortran format` - check the format of Fortran source files using `fprettify` |
| 201 | +* `Check python format` - check the python formatting using `ruff` |
| 202 | +* `Check python lint` - check python files for programmatic and stylistic errors using `ruff` |
| 203 | + |
| 204 | +The Fortran format task is only needed if the fortran formatter has not been [integrated with VSCode](#settings). |
| 205 | + |
| 206 | +### Additional tasks |
| 207 | + |
| 208 | +A number of additional VSCode tasks are available to perform common tasks that are required before making a Pull Request (see the [Developer documents](../DEVELOPER.md)). |
| 209 | + |
| 210 | +In order run additional tasks run: |
| 211 | + |
| 212 | +* Press `Ctrl + Shift + P` in VSCode. |
| 213 | +* Type `Tasks: Run Build Task` (press Enter). |
| 214 | +* Select the suitable task for your situation. |
| 215 | + |
| 216 | +Currently available additional tasks include: |
| 217 | + |
| 218 | +* `Run update_flopy.py` - updates FloPy MODFLOW 6 classes in the modflow6 Conda environment using current MODFLOW 6 definition files. |
| 219 | +* `Run dfn2f90.py` - updates Fortran definitions using current MODFLOW 6 definition files. |
| 220 | +* `Run mf6ivar.py` - Regenerates LaTeX file for the input output guide current MODFLOW 6 definition files. |
| 221 | +* `Rebuild makefiles` - Rebuilds the GNU makefile for MODFLOW 6 (`mf6`), ZONEBUDGET 6 (`zbud6`), and the MODFLOW Converter (`mf5to6`). |
0 commit comments