• Stars
    star
    212
  • Rank 186,122 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fortran language support for Visual Studio Code

Visual Studio Marketplace Downloads Visual Studio Marketplace Installs GitHub Workflow Status Visual Studio Marketplace Version (including pre-releases) GitHub

Key Features β€’ Get Started β€’ LSP β€’ Lint β€’ Debug β€’ Format β€’ Snippets β€’ Donate

Key Features

Get Started & Seek Support

Useful Tools

Language Server integration

The Fortran Language Server fortls is responsible for providing a lot of the higher level, IDE functionality. By default, Modern Fortran will attempt to use it for hover, autocompletion, symbols and Go to & Peeking into definitions.

Allow for fortls to be automatically installed with pip or Anaconda and if the location where fortls is installed is not in your PATH point VS Code to the fortls location by setting

{
  "fortran.fortls.path": "/custom/path/to/fortls"
}

For more about the Language Server's capabilities please refer to the documentation of fortls.

Linting

Linting allows for compiler error and warning detection while coding without the user having to compile.

Vendor Compiler
GNU gfortran
Intel ifort, ifx
NAG nagfor

Using an invalid if expression

alt

Using incorrect type and rank as function argument

alt

πŸ“οΈ Note Save your file to generate linting results

Linting results can be improved by providing additional options to the compiler.

Including directories

You can control the include paths to be used by the linter with the fortran.linter.includePaths option.

❗️ Important For the best linting results linter.includePaths should match the included paths for your project's compilation.
{
  "fortran.linter.includePaths": ["/usr/include/**", "${workspaceFolder}/include/**"]
}
❗️ Important If a glob pattern is used only directories matching the pattern will be included

Additional linting options

More options can be passed to the linter via

{
  "fortran.linter.extraArgs": [
    "-fdefault-real-8",
    "-fdefault-double-8",
    "-Wunused-variable",
    "-Wunused-dummy-argument"
  ]
}

Default value is -Wall (or -warn all for ifort).

Changing linting compiler

By default, the linter used is gfortran, Intel's ifort and Intel's LLVM based compiler ifx are also supported. One can use a different linter compiler via the option

{
  "fortran.linter.compiler": "ifort" | "gfortran" | "ifx" | "Disabled"
}

The linter executable is assumed to be found in the PATH. In order to use a different executable or if the executable can't be found in the PATH you can point the extension to another linter with the fortran.linter.compilerPath option.

{
  "fortran.linter.compilerPath": "/opt/oneapi/compiler/2022.0.2/linux/bin/intel64/ifort"
}

Debugging

alt

The extension uses the debugger from Microsoft's C/C++ extension for Visual Studio Code. This allows this extension to use the full functionality of the C/C++ extension for debugging applications: (un)conditional breaking points, expression evaluation, multithreaded debugging, call stack, stepping, watch window.

A minimal launch.json script, responsible for controlling the debugger, is provided below. However, Visual Studio Code is also capable of autogenerating a launch.json file and the configurations inside the file.

More details about how to set up the debugger can be found in Microsoft's website:

Example: Launch.json
{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "(gdb) Fortran",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/a.out",
      "args": [], // Possible input args for a.out
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}

Formatting

Two formatters are supported findent and fprettify. Both of them can be installed with pip automatically through the extension.

Demo: formatters in action
findent fprettify
alt alt

The formatter is controlled by the user option

{
  "fortran.formatting.formatter": "findent" | "fprettify" | "Disabled"
}

Additional arguments to the formatter can be input using

{
  "fortran.formatting.findentArgs": ["-Cn", "-Rr"],
  "fortran.formatting.fprettifyArgs": ["--whitespace-comma", "--enable-decl"]
}

To check all available arguments to formatters try findent -h or fprettify -h in a terminal.

If the formatter is not present in the PATH its location can be input with

{
  "fortran.formatting.path": "./custom/path/venv/bin"
}
πŸ“οΈ Note findent can also be used to generate dependency files for a project.

Fortran Package Manager

Validation of fpm.toml

Autocompletion and options validation for fpm.toml files are provided by the installing the Even Better TOML Visual Studio Code extension.

fpm-validation

Snippets

Snippets are included by both fortls Language Server and the Modern Fortran VS Code extension. Some available snippets can be seen below. Users can define their own snippets by following these VS Code instructions.

If you think a snippet should be shipped by with the extension feel free to submit a feature request

Demo: snippets in action

program snippet module snippet

Advanced options

To show the symbols in the file outline enable provide.symbols. Symbols can be served by the fortls, the built-in, both or none. By default fortls is used.

{
  "fortran.provide.symbols": "fortls" | "Built-in" | "Both" | "Disable"
}

You can also configure the case for fortran intrinsics auto-complete by using

{
    "fortran.preferredCase": "lowercase" | "uppercase"
}

Requirements

For debugging you need to have one of the following debuggers installed:

  • Linux: GDB
  • macOS: GDB or LLDB
  • Windows: GDB or Visual Studio Windows Debugger

Contributing

Support Us

You can support further development of the extension by fiscal donations:

to our LFortan project on NumFOCUS

Or

directly sponsoring developers through GitHub Sponsors

More Repositories

1

stdlib

Fortran Standard Library
Fortran
1,066
star
2

fpm

Fortran Package Manager (fpm)
Fortran
879
star
3

fprettify

auto-formatter for modern fortran source code
Python
373
star
4

fortls

fortls - Fortran Language Server
Python
249
star
5

fortran-lang.org

(deprecated) Fortran website
HTML
130
star
6

minpack

Modernized Minpack: for solving nonlinear equations and nonlinear least squares problems
Fortran
94
star
7

test-drive

The simple testing framework
Fortran
81
star
8

setup-fortran

GitHub action to setup Fortran compiler and toolchain
Shell
75
star
9

fftpack

Double precision version of fftpack
Fortran
67
star
10

http-client

http-client offers a user-friendly, high-level API to make HTTP requests in Fortran.
Fortran
58
star
11

webpage

New Fortran webpage
Python
47
star
12

fpm-registry

Centralized registry of fpm packages
Python
36
star
13

playground

An interactive Fortran playground
JavaScript
34
star
14

fpm-docs

Documentation repository for the Fortran package manager (fpm)
Fortran
34
star
15

setup-fpm

GitHub Action to setup the Fortran Package Manager for CI on Ubuntu, MacOS and Windows.
JavaScript
29
star
16

benchmarks

Fortran benchmarks
C
19
star
17

stdlib-docs

Documentation for https://github.com/fortran-lang/stdlib
HTML
18
star
18

homebrew-fortran

Homebrew tap for Fortran tooling and libraries
Ruby
13
star
19

talks

Repository for talks and presentations about fortran-lang projects
TeX
13
star
20

stdlib-cmake-example

Integration of the Fortran standard library in CMake projects
Fortran
13
star
21

fortran-forum-article-template

Article template for the ACM Fortran Forum
Shell
9
star
22

registry

Registry for Fortran package manager
JavaScript
8
star
23

fpm-metadata

Python model for Fortran package manifests
Python
6
star
24

fpm-on-wheels

Fortran package manager on wheels
Shell
4
star
25

assets

Assets, artwork and graphics for fortran-lang
HTML
3
star
26

fpm-haskell

The legacy Haskell implementation of fpm. No longer under active development.
Haskell
2
star
27

.github

Community-wide resources and default files for Fortran-lang
2
star