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 record stub generation off-by-one #905

Merged
merged 2 commits into from
Mar 27, 2022

Conversation

baronfel
Copy link
Contributor

Fixes ionide/ionide-vscode-fsharp#1674 by

  • addressing an off-by-one line read error introduced by the move to NamedText vs raw ISourceText, and
  • cleans up the record stub code by moving it to the core Syntax Tree Walker mechanism, and
  • fixes an edge case where stub generation wouldn't work if you were outside a field range, and
  • adds some basic testing

@@ -19,7 +19,7 @@ type CodeGenerationService(checker : FSharpCompilerServiceChecker, state : State
option {
let! text = state.TryGetFileSource fileName |> Option.ofResult
try
let! line = text.GetLine (Position.mkPos (i - 1) 0)
let! line = text.GetLine (Position.mkPos i 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the core issue - we don't need to do a -1 line position because this helper covers that already.

@@ -117,7 +117,10 @@ module CodeGenerationUtils =
range

let lineIdxAndTokenSeq = seq {
for lineIdx = range.StartLine to range.EndLine do
let lines =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cover edge cases where the line range is on the same line

@@ -20,6 +20,7 @@ type RecordExpr = {
Expr: SynExpr
CopyExprOption: option<SynExpr * BlockSeparator>
FieldExprList: SynExprRecordField list
LastKnownGoodPosForSymbolLookup: Position
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case we are at the end of a record declaration (e.g. the | in { a = "";| }), we need some kind of identifier to use to look up the symbol to find the record's type definition. this field allows us to grab that during the AST walk for later use.

new SyntaxVisitorBase<RecordExpr>() with
member x.VisitExpr(path: SyntaxVisitorPath, traverseSynExpr: (SynExpr -> _ option), defaultTraverse: (SynExpr -> _ option), synExpr: SynExpr) =
match synExpr with
| SynExpr.Record (recordFields = recordFields; copyInfo = copyInfo) ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a lot less code than the other version and expresses the majority of the same intent. any addition we want to make to this will be much easier in the standard walker.

@baronfel baronfel force-pushed the ionide-1674-record-stub-generation branch from 3680abe to 69dae0d Compare March 26, 2022 03:47
@baronfel baronfel force-pushed the ionide-1674-record-stub-generation branch from 69dae0d to 55aec5b Compare March 26, 2022 04:00
@baronfel baronfel merged commit 7d6f716 into ionide:main Mar 27, 2022
@baronfel baronfel deleted the ionide-1674-record-stub-generation branch March 27, 2022 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Record stub generation does not work
1 participant