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

Add GetSubTextFromRange to ISourceText #15979

Merged
merged 11 commits into from
Oct 9, 2023
Merged

Add GetSubTextFromRange to ISourceText #15979

merged 11 commits into from
Oct 9, 2023

Conversation

nojaf
Copy link
Contributor

@nojaf nojaf commented Sep 14, 2023

In Fantomas, we have an extension for ISourceText to grab the text based on a range.

I find myself copying this over to other projects that consume FCS quite often, and I would like to have this in FCS.

@nojaf nojaf requested a review from a team as a code owner September 14, 2023 14:33
src/Compiler/Facilities/prim-lexing.fs Outdated Show resolved Hide resolved
src/Compiler/Facilities/prim-lexing.fs Outdated Show resolved Hide resolved
@psfinaki
Copy link
Member

I'd say this can go in - but just trying to understand, can this be redesigned to actually not have duplicate implementations?

@nojaf
Copy link
Contributor Author

nojaf commented Sep 20, 2023

I guess, any suggestions on where to extract the code?

Copy link
Member

@psfinaki psfinaki left a comment

Choose a reason for hiding this comment

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

I guess at least this part

else
    (let sourceText = this :> ISourceText)
    let startLine = range.StartLine - 1
    let line = sourceText.GetLineString startLine
    ...

can be moved to a method in SourceText and then reused elsewhere.

@nojaf
Copy link
Contributor Author

nojaf commented Sep 27, 2023

The module SourceText is defined underneath the type.

module SourceText =

@T-Gro T-Gro merged commit d16af0e into dotnet:main Oct 9, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants