diff --git a/presentation-compiler/src/main/scala/org/alephium/ralph/lsp/pc/workspace/InheritedParentsResultSoft.scala b/presentation-compiler/src/main/scala/org/alephium/ralph/lsp/pc/workspace/InheritedParentsResultSoft.scala new file mode 100644 index 00000000..6e2c0fb5 --- /dev/null +++ b/presentation-compiler/src/main/scala/org/alephium/ralph/lsp/pc/workspace/InheritedParentsResultSoft.scala @@ -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]) diff --git a/presentation-compiler/src/main/scala/org/alephium/ralph/lsp/pc/workspace/WorkspaceSearcher.scala b/presentation-compiler/src/main/scala/org/alephium/ralph/lsp/pc/workspace/WorkspaceSearcher.scala index f9baec37..20e0d9dc 100644 --- a/presentation-compiler/src/main/scala/org/alephium/ralph/lsp/pc/workspace/WorkspaceSearcher.scala +++ b/presentation-compiler/src/main/scala/org/alephium/ralph/lsp/pc/workspace/WorkspaceSearcher.scala @@ -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.