Skip to content

Commit

Permalink
Implemented collectInheritedParentsSoft
Browse files Browse the repository at this point in the history
  • Loading branch information
simerplaha committed Mar 5, 2025
1 parent 4b768ea commit a5834ce
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 The Alephium Authors
// This file is part of the alephium project.
//
// The library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the library. If not, see http://www.gnu.org/licenses/.

package org.alephium.ralph.lsp.pc.workspace

import org.alephium.ralph.lsp.pc.sourcecode.SourceLocation

import scala.collection.immutable.ArraySeq

/**
* Result type for the function [[WorkspaceSearcher.collectInheritedParentsSoft]].
*
* @param parentTrees The resulting parent trees within the current workspace.
* @param allTrees All trees in scope within the current workspace.
*/
case class InheritedParentsResultSoft(
parentTrees: ArraySeq[SourceLocation.CodeSoft],
allTrees: ArraySeq[SourceLocation.CodeSoft])
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,32 @@ object WorkspaceSearcher {
)
}

/**
* Collects all parent source implementations inherited by the given source tree, excluding itself.
*
* @param sourceCode The source code for which in-scope files are being searched.
* @param workspace The workspace that may contain files within the scope.
* @return The source trees within the scope.
*/
def collectInheritedParentsSoft(
sourceCode: SourceLocation.CodeSoft,
workspace: WorkspaceState.IsSourceAware
)(implicit logger: ClientLogger): InheritedParentsResultSoft = {
val allInScopeCode =
collectTreesSoft(workspace = workspace, includeNonImportedCode = false)

val parents =
SourceCodeSearcher.collectInheritedParents(
source = sourceCode,
allSource = allInScopeCode
)

InheritedParentsResultSoft(
parentTrees = parents,
allTrees = allInScopeCode
)
}

/**
* Collects all children implementing or extending the given
* source tree and public contracts/structs.
Expand Down

0 comments on commit a5834ce

Please sign in to comment.