vscode-fortran-support icon indicating copy to clipboard operation
vscode-fortran-support copied to clipboard

Customizable line width past 72 characters in Fixed Form

Open tymric opened this issue 5 years ago • 8 comments

Description

In certain cases, some are shown below in the MWE, the syntax highlighting marks the 73rd character as a comment.

Request

Make the number of characters in a line that are coloured as input (and not comments) a user input variable.

MWE

C F77 MWE syntax highlighting breaking at line
      PROGRAM TEST

      integer :: i = 10
      ! Character 73 begins here -------------------------------------->
      print*, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i,
      print*, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i,i, i,
      print*, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i,i,i, i

      print*, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
      print*, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,18, 19

      print*, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, (1), 18, 19
      print*, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 18, 19

      END PROGRAM TEST

Highlighting

Screenshot from 2021-09-21 09-26-10


Original Post

Hi,

I use fixed-form Fortran with 132 columns. Visual Studio already has a setting for increasing the line width, but none of the VScode Fortran extensions have it. Is it possible to add the line width as a variable that can be changed in the settings? Thanks!

tymric avatar Aug 07 '18 08:08 tymric

Hey, thanks for creating an issue. Can you elaborate more on this? Like what kind of behaviour are you expecting to see. And how that is not possible to be accomplished by VS Code itself?

krvajal avatar Oct 14 '18 09:10 krvajal

Hi, thanks for the response! In gfortran, there is the option -ffixed-line-length-n which controls the column after which characters are ignored and treated as comments.

from here:

Popular values for n include 72 (the standard and the default), 80 (card image), and 132 (corresponding to “extended-source” options in some popular compilers)

In its current state, the syntax highlighting for fixed-form Fortran in the extension only supports a line length of 72 characters. Anything after column 72 appears as comments (green) in the source code, which also affects the appearance of the following lines (when a closing parenthesis is in this green region for example)

The software I work with uses a line length of 132. So a desired behavior in such case would be to include a option (fortran.fixedLineLength for example) which allows the user to control the value of n of fixed form files both for the compiler and the syntax highlighting.

tymric avatar Oct 16 '18 11:10 tymric

I know where this option is in our extension, but don't know how to make it variable since it's hardcoded inside a json file fortran_fixed-form.tmLanguage.json. That line-end-comment scope controls exactly what you want.

pedro-ricardo avatar Oct 16 '18 11:10 pedro-ricardo

Thats a tricky problem. Maybe having instead of only one option we can add those other common ones like you mentioned?

krvajal avatar Oct 16 '18 11:10 krvajal

Thats a tricky problem. Maybe having instead of only one option we can add those other common ones like you mentioned?

That'd be a great option as well. It is how Intel Fortran Compiler is configured in Visual Studio Pro, so it must be safe to assume only these 3 options (see screenshot) image

tymric avatar Oct 16 '18 12:10 tymric

@krvajal Can you guide me in this? ... Everywhere i look the syntax of fortran_fixed-form is set by .json files... I thought about creating different .json files having only line-end-comment scope, somethig like:

  • line_end_72.json
  • line_end_80.json
  • line_end_132.json

and including them in fortran_fixed-form.tmLanguage.json as set by a configuration variable. To make this If and access the extension configuration, i believe i need a .ts file And i got no idea how or where to do it ! =]

pedro-ricardo avatar Oct 31 '18 12:10 pedro-ricardo

It appears that we are not the only ones with a need to dynamically generate grammars. This issue is being tracked here https://github.com/microsoft/vscode/issues/68647 . Some workarounds have been offered

gnikit avatar Nov 26 '21 20:11 gnikit

@tymric please let me know if you found any solution to this problem.

shivakumargaddam avatar May 23 '24 14:05 shivakumargaddam