-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lsp): Plugin throws OOM on big projects (#1134)
- Loading branch information
Showing
7 changed files
with
102 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
semantics/src/main/scala/aqua/semantics/rules/locations/Variables.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package aqua.semantics.rules.locations | ||
|
||
import aqua.helpers.syntax.list.* | ||
import aqua.parser.lexer.Token | ||
|
||
import cats.kernel.{Monoid, Semigroup} | ||
import cats.syntax.align.* | ||
|
||
case class Variables[S[_]]( | ||
variables: Map[String, List[VariableInfo[S]]] = Map.empty[String, List[VariableInfo[S]]] | ||
) { | ||
|
||
def renameDefinitions(f: PartialFunction[String, String]): Variables[S] = | ||
copy(variables = variables.map { case (k, v) => | ||
f.andThen { newName => | ||
newName -> v.map(vi => vi.copy(definition = vi.definition.copy(name = newName))) | ||
}.orElse { _ => | ||
k -> v | ||
}(k) | ||
}) | ||
|
||
lazy val allLocations: List[TokenLocation[S]] = | ||
variables.values.flatMap(_.flatMap(_.allLocations)).toList | ||
|
||
lazy val definitions: List[DefinitionInfo[S]] = | ||
variables.values.flatMap(_.map(_.definition)).toList | ||
|
||
def addDefinitions(newDefinitions: List[DefinitionInfo[S]]): Variables[S] = { | ||
copy(variables = | ||
newDefinitions | ||
.map(d => d.name -> List(VariableInfo(d))) | ||
.toMap | ||
.alignCombine(variables) | ||
) | ||
} | ||
|
||
/** | ||
* Add occurrance by name to the first (last added) definition. | ||
*/ | ||
def addOccurence( | ||
name: String, | ||
token: Token[S] | ||
): Variables[S] = { | ||
copy(variables = | ||
variables.updatedWith(name)( | ||
_.map( | ||
_.updateFirst( | ||
_.definition.name == name, | ||
v => v.copy(occurrences = token +: v.occurrences) | ||
) | ||
) | ||
) | ||
) | ||
} | ||
} | ||
|
||
object Variables { | ||
|
||
given [S[_]]: Semigroup[Variables[S]] with { | ||
|
||
override def combine(x: Variables[S], y: Variables[S]): Variables[S] = | ||
Variables(x.variables.alignCombine(y.variables).view.mapValues(_.distinct).toMap) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters