├── .vscode ├── launch.json └── tasks.json ├── README.md ├── public └── cursiveItalicsAndLigature.png └── src └── program.f90 /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "configurations": [ 4 | { 5 | "name": "Debug Fortran, build gfortran", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "targetArchitecture": "x86", 9 | "program": "${workspaceRoot}\\${fileBasenameNoExtension}.exe", 10 | "miDebuggerPath": "gdb.exe", 11 | "args": [], 12 | "stopAtEntry": false, 13 | "cwd": "${workspaceRoot}", 14 | "externalConsole": true, 15 | "preLaunchTask": "build_gfortran" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "_runner": "terminal", 4 | "tasks":[ 5 | { 6 | "label": "build_gfortran", 7 | "type": "shell", 8 | "windows": { 9 | "command": "gfortran" 10 | }, 11 | "linux": { 12 | "command": "gfortran" 13 | }, 14 | "osx": { 15 | "command": "gfortran" 16 | }, 17 | "args": [ 18 | "-g", 19 | "${file}", 20 | "-o", 21 | "${workspaceRoot}\\${fileBasenameNoExtension}.exe" 22 | ] 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | Fortran is not well supported by a lot of IDEs. 4 | Microsoft Visual Studio has syntax highlighting but missing a lot of great features, when it comes to auto completion, signature help, find and peek references. 5 | Visual Studio Code in comparison has some great extensions and is running on MacOs, Linux and Windows. 6 | 7 | This small Guide should help you to setup a full development environment for Fortran. 8 | 9 | # Visual Studio Code 10 | 11 | * Description: 12 | > Code editing. Redefined. Free. Built on open source. Runs everywhere [[https://code.visualstudio.com/](https://code.visualstudio.com/)]. 13 | * GitHub: [https://github.com/microsoft/vscode](https://github.com/microsoft/vscode) 14 | * Download and Install: 15 | * Windows: `choco install vscode`, [https://code.visualstudio.com/download](https://code.visualstudio.com/download) 16 | * Linux: [https://code.visualstudio.com/download](https://code.visualstudio.com/download) 17 | * OSX: [https://code.visualstudio.com/download](https://code.visualstudio.com/download) 18 | 19 | ## Editor Rulers 20 | 21 | If you are working with Fortran in the fixed-column format it is useful to setup rulers at the relevant columns. 22 | Add this to your `settings.json`: 23 | 24 | ```json 25 | "[FortranFixedForm]": { 26 | "editor.rulers": [ 27 | { 28 | "column": 72, 29 | "color": "#E06C75" 30 | }, 31 | { 32 | "column": 6, 33 | "color": "#E06C75" 34 | } 35 | ] 36 | }, 37 | ``` 38 | 39 | ## Cursive italics and Ligature 40 | 41 | Some might like this and some wont: Using cursive italics and programming symbol ligatures. 42 | 43 | ![code snippet](https://github.com/JHenneberg/Guide_VSCode-fortran/blob/master/public/cursiveItalicsAndLigature.png) 44 | 45 | 1. Download the font 'Victor Mono' from here: [https://github.com/rubjo/victor-mono](https://github.com/rubjo/victor-mono) or here [https://rubjo.github.io/victor-mono/](https://rubjo.github.io/victor-mono/) 46 | 47 | 2. Activate font ligatures and select the font: 48 | 49 | ```json 50 | "editor.fontLigatures": true, 51 | "editor.fontFamily": "Victor Mono, Consolas, 'Courier New', monospace", 52 | ``` 53 | 54 | 3. In the standard settings for fortran syntax highlighting nothing more then paramter are italic and therefore then cursive. You can customize this quite easy: 55 | 56 | ```json 57 | "editor.tokenColorCustomizations": { 58 | "textMateRules": [ 59 | { 60 | "name": "comment", 61 | "scope": [ 62 | "comment", 63 | "constant.language.logical", 64 | "keyword.logical", 65 | "variable.parameter.dummy-variable.fortran.modern", 66 | "string.quoted.single.fortran", 67 | "string.quoted.double.fortran", 68 | "support.function.intrinsic.fortran" 69 | ], 70 | "settings": { 71 | "fontStyle": "italic" 72 | } 73 | }, 74 | { 75 | "name": "comment", 76 | "scope": [ 77 | "variable.parameter.fortran" 78 | ], 79 | "settings": { 80 | "fontStyle": "" 81 | } 82 | } 83 | ] 84 | } 85 | ``` 86 | 87 | To find out the scope you can type in the command palette (`ctrl` + `shift` + `p`): `Developer: Inspect Editor Tokens and Scopes` and hover over your source code. 88 | 89 | # Visual Studio Code Extensions 90 | 91 | There are some extensions that are very useful. 92 | `Modern Fortran` can be used for syntax highlighting and snippets. 93 | For features like Signature help or GoTo/Peek definition and much more `fortls` should be installed. 94 | 95 | ## Modern Fortran 96 | 97 | ### Overview 98 | 99 | * Description: 100 | > This extension provides support for the Fortran programming language. It includes syntax highlighting, code snippets and a linting based on `gfortran`, `ifort` and `ifx` [[https://github.com/fortran-lang/vscode-fortran-support](https://github.com/fortran-lang/vscode-fortran-support)]. 101 | * GitHub: [https://github.com/fortran-lang/vscode-fortran-support](https://github.com/fortran-lang/vscode-fortran-support) 102 | * Download: [https://marketplace.visualstudio.com/items?itemName=fortran-lang.linter-gfortran](https://marketplace.visualstudio.com/items?itemName=fortran-lang.linter-gfortran) 103 | * Optional Requirements: 104 | * `fortls` 105 | 106 | ### Language Server Integration 107 | 108 | Symbol functionality and hover information is also provided by `Modern Fortran` when the fortran language server `fortls` is installed which is written in python. 109 | 110 | ### Requirements 111 | 112 | 1. Install `python` 113 | 2. Install `pip` 114 | 3. Install `fortls` 115 | 116 | * Python: 117 | 118 | * Description: 119 | * GitHub: https://github.com/python 120 | * Download and Install: 121 | * Windows: `choco install python`, [https://www.python.org/downloads/windows/](https://www.python.org/downloads/windows/) 122 | * Linux: `sudo apt-get install python3`, `pacman -S python` | `pacman -S python2` 123 | * OSX: [https://www.python.org/downloads/mac-osx/](https://www.python.org/downloads/mac-osx/) 124 | 125 | * pip: 126 | 127 | * Description: 128 | >pip is the package installer for Python. You can use pip to install packages from the Python Package Index and other indexes [[https://github.com/pypa/pip](https://github.com/pypa/pip)]. 129 | * GitHub: https://github.com/pypa/pip 130 | * Download and Install: 131 | * Windows: it is often already installed during the installation process of python itself https://pip.pypa.io/en/stable/installing/ 132 | * Linux: https://pip.pypa.io/en/stable/installing/ 133 | * OSX: https://pip.pypa.io/en/stable/installing/ 134 | 135 | * fortls: 136 | 137 | * Description: 138 | >A Fortran implementation of the Language Server Protocol (LSP) using Python (3.6+). 139 | Editor extensions that can integrate with fortls to provide autocomplete and other IDE-like functionality are available for Visual Studio Code Atom, Visual Studio, (Neo)vim, and Emacs.[[https://github.com/gnikit/fortls](https://github.com/gnikit/fortls)]. 140 | * GitHub: https://github.com/gnikit/fortls 141 | * Download and Install: 142 | * Windows: `python -m pip install fortls` 143 | * Linux: `pip install fortls` 144 | * OSX: `pip install fortls` 145 | * Update: 146 | * Windows: `python -m pip install --upgrade fortls` 147 | * Linux: `pip install --upgrade fortls` 148 | * OSX : `pip install --upgrade fortls` 149 | 150 | ### Settings 151 | 152 | To setup `fortls` a file named `.fortls` is needed in your workspace in Visual Studio Code. 153 | It is written in JSON. 154 | Example `.fortls`: 155 | 156 | ```json 157 | { 158 | "mod_dirs": [ 159 | "src", 160 | "ins" 161 | ], 162 | "excl_paths": ["src/Debug", "src/Release"], 163 | "excl_suffixes": [".u2d", ".vfproj", ".sln", ".txt"], 164 | "lowercase_intrinsics": false, 165 | "debug_log": false 166 | } 167 | ``` 168 | 169 | # Build & Debug 170 | 171 | In general you have to define a `tasks.json` for the build and link process and a `launch.json` to start to debug. 172 | 173 | Also have a look at: https://code.visualstudio.com/docs/editor/debugging 174 | 175 | ## Install compiler 176 | 177 | * Windows: gfortran via MinGW for example 178 | * Linux: `sudo apt-get install gfortran`, `sudo pacman -S gcc-fortran` 179 | * OSX: 180 | 181 | ## Create launch.json: 182 | 183 | ```JSON 184 | { 185 | "version": "2.0.0", 186 | "configurations": [ 187 | { 188 | "name": "Debug Fortran & build", 189 | "type": "cppdbg", 190 | "request": "launch", 191 | "targetArchitecture": "x86", 192 | "program": "${workspaceRoot}\\${fileBasenameNoExtension}.exe", 193 | "miDebuggerPath": "gdb.exe", 194 | "args": [], 195 | "stopAtEntry": false, 196 | "cwd": "${workspaceRoot}", 197 | "externalConsole": true, 198 | "preLaunchTask": "build_gfortran" 199 | } 200 | ] 201 | } 202 | ``` 203 | 204 | ## Create tasks.json 205 | 206 | The `gfortran` compiler should be accessible via the command line. 207 | 208 | Create `tasks.json`: 209 | 210 | ```JSON 211 | { 212 | "version": "2.0.0", 213 | "_runner": "terminal", 214 | "tasks":[ 215 | { 216 | "label": "build_gfortran", 217 | "type": "shell", 218 | "windows": { 219 | "command": "gfortran" 220 | }, 221 | "linux": { 222 | "command": "gfortran" 223 | }, 224 | "osx": { 225 | "command": "gfortran" 226 | }, 227 | "args": [ 228 | "-g", 229 | "${file}", 230 | "-o", 231 | "${workspaceRoot}\\${fileBasenameNoExtension}.exe" 232 | ] 233 | } 234 | ], 235 | } 236 | ``` 237 | 238 | ## Debugging 239 | 240 | Click on the debug symbol in Visual Studio Code, choose the debug configuration and press start. 241 | -------------------------------------------------------------------------------- /public/cursiveItalicsAndLigature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JHenneberg/Guide_VSCode-fortran/e945be717fa4f1cfe6c43d83fa7bf1051f495c1c/public/cursiveItalicsAndLigature.png -------------------------------------------------------------------------------- /src/program.f90: -------------------------------------------------------------------------------- 1 | program nonesense 2 | implicit none 3 | 4 | real(8) :: r_I(4), s_I(4) 5 | 6 | call get_natural_coordinates_quadrilateral(r_I, s_I) 7 | 8 | if (r_I(1) >= 0.d0) then 9 | write(*, *) r_I(4) 10 | else if (all(r_I(:) /= 0.d0)) then 11 | write(*, *) r_I(3) 12 | end if 13 | end program nonesense 14 | 15 | 16 | subroutine get_natural_coordinates_quadrilateral(r_I, s_I) 17 | ! 2005, Zienkiewicz, 'The Finite Element Method, Its Basis & Fundamentals', 6th Edition, p.157 18 | implicit none 19 | 20 | real(8), intent(out) :: r_I(4), s_I(4) 21 | 22 | r_I = [-1.d0, +1.d0, +1.d0, -1.d0] 23 | s_I = [-1.d0, -1.d0, +1.d0, +1.d0] 24 | end subroutine get_natural_coordinates_quadrilateral --------------------------------------------------------------------------------