Skip to content

Commit 45b8638

Browse files
authored
Merge branch 'main' into feature/1010-pom-leading-for-dsls/final
2 parents 5b79269 + 914cac2 commit 45b8638

10 files changed

Lines changed: 170 additions & 128 deletions

File tree

rascal-lsp/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<dependency>
6565
<groupId>org.rascalmpl</groupId>
6666
<artifactId>rascal</artifactId>
67-
<version>0.43.0-RC7</version>
67+
<version>0.43.0-RC8</version>
6868
</dependency>
6969
<!-- Rascal tests require JUnit 4 -->
7070
<dependency>

rascal-lsp/src/main/rascal/lsp/lang/rascal/lsp/Actions.rsc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ bool isFixableAnnoSyntax((Expression) `delAnnotationsRec(<Expression _>)`)
101101
bool isFixableAnnoSyntax((Expression) `delAnnotation(<Expression _>, <Expression _>)`)
102102
= true;
103103

104-
bool isFixableAnnoSyntax((Expression) `delAnnotation(<Expression _>, <Expression _>)`)
105-
= true;
106-
107104
bool isFixableAnnoSyntax((Catch) `catch NoSuchAnnotation(<Pattern _>) : <Statement _>`)
108105
= true;
109106

rascal-lsp/src/main/rascal/lsp/lang/rascal/lsp/refactor/Rename.rsc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,18 @@ import analysis::diff::edits::AnnotatedTextEdits;
7474
private bool isQualifiedUse(loc use, Define _:<_, str id, _, _, _, _>) = size(id) != use.length;
7575

7676
void rascalCheckCausesOverlappingDefinitions(set[Define] currentDefs, str newName, Tree tr, TModel tm, Renamer r) {
77-
defUse = invert(tm.useDef);
77+
useDef = getUseDef(tm);
78+
defUse = invert(useDef);
7879
unescNewName = forceUnescapeNames(newName);
7980
reachable = rascalGetReflexiveModulePaths(tm).to;
80-
usedModules = {d.top | loc d <- tm.useDef<1>};
81+
usedModules = {d.top | loc d <- useDef<1>};
8182
usedModels = (m: tm | loc m <- usedModules, TModel tm := r.getConfig().tmodelForLoc(m)) + (tr.src.top: tm);
8283
newNameDefs = {nD | TModel tm <- range(usedModels), Define nD:<_, unescNewName, _, _, _, _> <- tm.defines};
8384
curAndNewDefinitions = (d.defined: d | d <- currentDefs + newNameDefs); // temporary map for overloading checks
8485
maybeImplicitDefs = {n.names[-1].src | /QualifiedName n := tr};
8586
8687
bool isImplicitDef(Define d)
87-
= (d.idRole is variableId && d.defined in tm.useDef<0>) // variable that's both a use and a def
88+
= (d.idRole is variableId && d.defined in useDef<0>) // variable that's both a use and a def
8889
|| (d.idRole is patternVariableId && d.defined in maybeImplicitDefs) // or pattern variable without a type
8990
;
9091
@@ -304,7 +305,7 @@ private set[Define] tryGetCursorDefinitions(list[Tree] cursor, TModel(loc) getMo
304305
if (tm.definitions[c.src]?) {
305306
// Cursor at definition
306307
cursorDefs = {tm.definitions[c.src]};
307-
} else if (defs: {_, *_} := tm.useDef[c.src]) {
308+
} else if (defs: {_, *_} := getUseDef(tm)[c.src]) {
308309
// Cursor at use
309310
cursorDefs = flatMapPerFile(defs, set[Define](loc f, set[loc] localDefs) {
310311
localTm = f.top == cursorLoc.top ? tm : getModel(f);
@@ -404,7 +405,7 @@ void renameUses(set[Define] defs, str newName, TModel tm, Renamer r) {
404405
tm = getConditionallyAugmentedTModel(getModuleScopes(tm)[tm.modelName].top, defs, {augmentUses()}, r);
405406

406407
definitions = {<d.defined, d> | d <- defs};
407-
useDefs = toMap(tm.useDef o definitions);
408+
useDefs = toMap(getUseDef(tm) o definitions);
408409
for (loc u <- useDefs) {
409410
if (set[Define] ds:{_, *_} := useDefs[u], u notin defs.defined) {
410411
r.textEdit(replace(nameSuffix(u, ds, r), escName));

rascal-lsp/src/main/rascal/lsp/lang/rascal/lsp/refactor/rename/Common.rsc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ bool isContainedInScope(loc l, loc scope, TModel tm) {
6868

6969
loc getModuleFile(TModel tm) = getModuleScopes(tm)[tm.modelName].top;
7070

71+
@synopsis{
72+
Gets the use-def relation of TModel `tm`. Unlike `tm.useDef`, this function
73+
guarantees that the range of the relation is a subset of the domain of
74+
`tm.definitions`. Thus, unlike pairs in `tm.useDef`, if `<u, d>` is a pair
75+
in the relation, then `d` can safely be used to index `tm.definitions`.
76+
}
77+
rel[loc, loc] getUseDef(TModel tm) {
78+
map[loc, loc] id2define = invertUnique(tm.define2id);
79+
return {<u, id2define[d] ? d> | <loc u, loc d> <- tm.useDef};
80+
}
81+
7182
private set[str] reservedNames = getRascalReservedIdentifiers();
7283

7384
str forceUnescapeNames(str name) = replaceAll(name, "\\", "");

rascal-lsp/src/main/rascal/lsp/lang/rascal/lsp/refactor/rename/Fields.rsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ set[Define] getFieldDefinitions(set[AType] containerTypes, str fieldName, TModel
7979

8080
@synopsis{Collect all definitions for the field <fieldName> in ADT/collection/tuple by tree.}
8181
set[Define] getFieldDefinitions(Tree container, str fieldName, TModel tm, TModel(loc) getModel) {
82-
if (defs:{_, *_} := tm.useDef[container.src]) {
82+
if (defs:{_, *_} := getUseDef(tm)[container.src]) {
8383
return flatMapPerFile(defs, set[Define](loc f, set[loc] localContainerDefs) {
8484
fileTm = getModel(f);
8585

rascal-lsp/src/main/rascal/lsp/lang/rascal/lsp/refactor/rename/Modules.rsc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ void renameDefinitionUnchecked(Define d:<_, currentName, _, moduleId(), _, _>, l
136136
void renameAdditionalUses(set[Define] _:{<_, str moduleName, _, moduleId(), loc modDef, _>}, str newName, TModel tm, Renamer r) {
137137
// We get the module location from the uses. If there are no uses, this is skipped.
138138
// That's intended, since this function is only supposed to rename uses.
139-
if ({loc u, *_} := tm.useDef<0>) {
140-
for (/QualifiedName qn := r.getConfig().parseLoc(u.top), any(d <- tm.useDef[qn.src], d.top == modDef.top),
139+
rel[loc, loc] useDef = getUseDef(tm);
140+
if ({loc u, *_} := useDef<0>) {
141+
for (/QualifiedName qn := r.getConfig().parseLoc(u.top), any(d <- useDef[qn.src], d.top == modDef.top),
141142
just(<moduleName, prefLoc>) := qualifiedPrefix(qn)) {
142143
r.textEdit(replace(prefLoc, newName));
143144
}

rascal-lsp/src/main/rascal/lsp/lang/rascal/lsp/refactor/rename/Parameters.rsc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ TModel augmentFormalUses(Tree tr, TModel tm, TModel(loc) getModel) {
5454
| loc f <- getModuleFile(tm) + (tm.paths<to>)
5555
, fileTm := getModel(f.top)
5656
};
57+
rel[loc, loc] useDef = getUseDef(tm);
5758
visit (tr) {
5859
case (Expression) `<Expression e>(<{Expression ","}* _> <KeywordArguments[Expression] kwArgs>)`: {
59-
funcKwDefs = keywordFormalDefs[tm.useDef[e.src]];
60+
funcKwDefs = keywordFormalDefs[useDef[e.src]];
6061
// Only visit uses of our keyword arguments - do not go into nested calls
6162
top-down-break visit (kwArgs) {
6263
case (KeywordArgument[Expression]) `<Name kw> = <Expression _>`: {

0 commit comments

Comments
 (0)