Skip to content

Commit 747c041

Browse files
committed
Remove edit helper for repeating the last clause head when writing recursive predicates
1 parent 6846300 commit 747c041

File tree

3 files changed

+2
-106
lines changed

3 files changed

+2
-106
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## [0.24.0]
44

5-
* Add syntax highlighting of the new `consistency_error/3` built-in method
5+
* Remove edit helper for repeating the last clause head when writing recursive predicates
6+
* Add syntax highlighting and snippet for the new `consistency_error/3` built-in method
67

78
## [0.23.0]
89

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ For details, see [Configuration](#configuration). This extension includes a walk
4242

4343
- Indentation after new line
4444
- Built-in directive, method, and predicate template auto-completion
45-
- Auto-complete recursive parameters: When `.` (dot) occurs as first non-space character, this extension will repeat the nearest above head of clause and automatically change the parameters if possible.
4645

4746
Note: Relations between entities use choice snippets: `orel` triggers object relation choices and `crel` for category. There is only one relation between protocols, 'extends', so `ext` will trigger the snippet.
4847

src/features/editHelpers.ts

-104
Original file line numberDiff line numberDiff line change
@@ -72,108 +72,4 @@ export function loadEditHelpers(subscriptions: Disposable[]) {
7272
]
7373
})
7474
);
75-
76-
function getPreviousClauseHead(doc: TextDocument, line: number): string {
77-
if (line <= 0) {
78-
return "";
79-
}
80-
let txt = doc.lineAt(line).text;
81-
let regex = new RegExp("^\\s*(.+)(:-|-->)");
82-
if (regex.test(txt)) {
83-
return txt.match(regex)[1];
84-
}
85-
86-
regex = new RegExp("^\\s*(.+)\\.$");
87-
if (regex.test(txt)) {
88-
let i = line - 1;
89-
while (/^\s*$/.test(doc.lineAt(i).text)) i--;
90-
if (doc.lineAt(i).text.endsWith(".")) {
91-
return txt.match(regex)[1];
92-
}
93-
}
94-
95-
return getPreviousClauseHead(doc, line - 1);
96-
}
97-
98-
function isRecursive(doc: TextDocument, line: number) {
99-
if (line <= 0) {
100-
return false;
101-
}
102-
let i = line - 1;
103-
while (/^\s*$/.test(doc.lineAt(i).text)) i--;
104-
return /,$|:-$/.test(doc.lineAt(i).text) ? true : false;
105-
}
106-
107-
function nextRecursiveParams(
108-
doc: TextDocument,
109-
line: number,
110-
originalHead: string
111-
): string {
112-
if (!/\(/.test(originalHead)) {
113-
return originalHead;
114-
}
115-
let regex = new RegExp("([^(]+)\\((.+)\\)\\s*$");
116-
let match = originalHead.match(regex);
117-
let origList = match[2].split(",");
118-
let newList = origList.map(param => {
119-
let param1 = param.trim();
120-
let match = param1.match(/^\[.+\|(.+)\]$/);
121-
if (match) {
122-
return match[1];
123-
} else if (/^[A-Z]/.test(param1)) {
124-
let i = line;
125-
while (!/:-/.test(doc.lineAt(i).text)) {
126-
let match = doc
127-
.lineAt(i)
128-
.text.match("^\\s*(\\w+)\\s+is\\s+.*\\b" + param1 + "\\b");
129-
if (match) {
130-
return match[1];
131-
} else {
132-
i--;
133-
}
134-
}
135-
return param1;
136-
} else return param1;
137-
});
138-
return match[1] + "(" + newList.join(", ") + ")";
139-
}
140-
141-
workspace.onDidChangeTextDocument(
142-
e => {
143-
let lastChange = e.contentChanges[0];
144-
if (lastChange === undefined) {
145-
return;
146-
}
147-
let lastChar = lastChange.text;
148-
let range = lastChange.range;
149-
let start = range.start;
150-
let line = start.line;
151-
let col = start.character;
152-
let editor = window.activeTextEditor;
153-
let lineTxt = e.document.lineAt(line).text;
154-
if (/^\s*\.$/.test(lineTxt)) {
155-
let prevHead: string = getPreviousClauseHead(e.document, line - 1);
156-
if (isRecursive(e.document, line)) {
157-
prevHead = nextRecursiveParams(e.document, line - 1, prevHead);
158-
}
159-
editor
160-
.edit(edit => {
161-
edit.replace(
162-
new Range(start, new Position(line, col + 1)),
163-
prevHead
164-
);
165-
})
166-
.then(() => {
167-
let loc = prevHead.indexOf("(");
168-
loc = loc > -1 ? loc + 1 : prevHead.length - 1;
169-
let end = new Position(line, col + loc);
170-
editor.selection = new Selection(end, end);
171-
});
172-
} else {
173-
return;
174-
}
175-
},
176-
null,
177-
subscriptions
178-
);
17975
}

0 commit comments

Comments
 (0)