Skip to content

Commit a4a5bb4

Browse files
committed
Add "Check Code Portability" command to check the portability of loaded files
1 parent d2c2e34 commit a4a5bb4

6 files changed

Lines changed: 89 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [0.89.0]
44

5+
* Add "Check Code Portability" command to check the portability of loaded files
56
* Format Logtalk source files when saving them depending on the `editor.formatOnSave` setting
67

78
## [0.88.4]

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A VSCode extension that provides language support for Logtalk. Forked from the [original extension](https://github.com/arthwang/vsc-logtalk) by Arthur Wang.
44

5-
Requires **Logtalk 3.97.0** or later and a supported [Prolog backend](https://logtalk.org/download.html#requirements). As this extension uses supporting code that's part of the Logtalk distribution, use of the latest Logtalk version is strongly recommended.
5+
Requires **Logtalk 3.99.0** or later and a supported [Prolog backend](https://logtalk.org/download.html#requirements). As this extension uses supporting code that's part of the Logtalk distribution, use of the latest Logtalk version is strongly recommended.
66

77
🙏 Sponsored by [Permion](https://permion.ai/) and [GitHub Sponsors](https://github.com/sponsors/pmoura).
88

@@ -184,6 +184,7 @@ Project (workspace) commands can be triggered from the command palette by typing
184184
| Open Logtalk | Opens Logtalk in an integrated terminal |
185185
| Make | Sub-menu with available make targets |
186186
| Scan Project Dead Code | Recursively scans the workspace root folder for dead code |
187+
| Check Code Portability | Checks loaded code portability |
187188
| Compute Project Metrics | Recursively computes metrics for the workspace root folder |
188189
| Profiling | Sub-menu with code profiling commands |
189190
| Generate Project Documentation | Recursively generates documentation for the workspace root folder |
@@ -198,6 +199,8 @@ The "Load Project" command looks for a `loader.lgt` or `loader.logtalk` file in
198199

199200
The "Create Loader File" command creates a `loader.lgt` file from selected Logtalk files or from all Logtalk files in a selected directory. When multiple Logtalk files are selected in the explorer, it creates a loader file containing all selected files. When a directory is selected, it finds all `.lgt` and `.logtalk` files in that directory and also includes any `loader.lgt` files found in immediate subdirectories. The command filters only Logtalk files, removes duplicates, sorts them alphabetically, and prompts for confirmation before overwriting an existing `loader.lgt` file. The created file is automatically opened after creation.
200201

202+
The "Check Code Portability" command reloads all files by calling `logtalk_make(force)` with the `portability` flag set to `warning`. But note that all linter warnings will be reported and added to the "Problems" pane, not just portability warnings.
203+
201204
The "Scan Project Dead Code", "Compute Project Metrics", "Generate Project Documentation", and "Generate Project Diagrams" commands require that the project code is already loaded. Quick fixes are provided for some of the documentation and dead code linter warnings.
202205

203206
The output of the "Run Project Testers" and "Run Project Doclets" commands is displayed in the "OUTPUT" pane "Logtalk Testers & Doclets" channel. The "Run Project Testers" command adds failed tests to the "PROBLEMS" pane.
@@ -217,6 +220,7 @@ These commands can be triggered from the editor/context menu via right-click in
217220
| Open Parent File | Opens the file that loaded the active source file if any |
218221
| Make | Sub-menu with available make targets |
219222
| Scan Dead Code | Scans the active source file directory for dead code |
223+
| Check Code Portability | Checks loaded code portability |
220224
| Compute Metrics | Computes metrics for all files in the active source file directory |
221225
| Profiling | Sub-menu with code profiling commands |
222226
| Generate Documentation | Generates documentation for the active source file directory |
@@ -231,7 +235,7 @@ The "Load Directory" command looks for a `loader.lgt` or `loader.logtalk` file i
231235

232236
The "Run Tests" and "Run Tests with Coverage" commands add failed tests to the "PROBLEMS" pane. Quick fixes are provided for some test definition warnings.
233237

234-
The "Generate Documentation" and "Scan Dead Code" commands add linter warnings to the "PROBLEMS" pane. Quick fixes are provided for some of the warnings.
238+
The "Generate Documentation", "Scan Dead Code", and "Check Code Portability" commands add linter warnings to the "PROBLEMS" pane. Quick fixes are provided for some of the warnings.
235239

236240
The output of the "Generate Documentation" and "Generate Diagrams" commands assume that the documentation and the diagrams will be browsed locally in VSCode (with the entry point being the main diagram, which can be opened using the "Open SVG in Viewer" command). The default output directories are `xml_docs` for documentation and `dot_dias` for diagrams. To generate documentation and diagrams for publication, define a _doclet_ and run it using the "Run Doclet" command.
237241

package.json

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@
148148
"title": "Scan Dead Code",
149149
"category": "Logtalk"
150150
},
151+
{
152+
"command": "logtalk.check.codePortability",
153+
"title": "Check Code Portability",
154+
"category": "Logtalk"
155+
},
151156
{
152157
"command": "logtalk.run.doclet",
153158
"title": "Run Doclet",
@@ -496,6 +501,10 @@
496501
"command": "logtalk.scan.deadCode",
497502
"when": "!virtualWorkspace"
498503
},
504+
{
505+
"command": "logtalk.check.codePortability",
506+
"when": "!virtualWorkspace"
507+
},
499508
{
500509
"command": "logtalk.compute.metrics",
501510
"when": "!virtualWorkspace"
@@ -663,15 +672,20 @@
663672
"group": "directory_2@1"
664673
},
665674
{
666-
"command": "logtalk.compute.metrics",
675+
"command": "logtalk.check.codePortability",
667676
"when": "resourceLangId == logtalk && !virtualWorkspace",
668677
"group": "directory_2@2"
669678
},
670679
{
671-
"submenu": "profilingsubmenu",
680+
"command": "logtalk.compute.metrics",
672681
"when": "resourceLangId == logtalk && !virtualWorkspace",
673682
"group": "directory_2@3"
674683
},
684+
{
685+
"submenu": "profilingsubmenu",
686+
"when": "resourceLangId == logtalk && !virtualWorkspace",
687+
"group": "directory_2@4"
688+
},
675689
{
676690
"command": "logtalk.generate.documentation",
677691
"when": "resourceLangId == logtalk && !virtualWorkspace",
@@ -740,15 +754,20 @@
740754
"group": "project_2@1"
741755
},
742756
{
743-
"command": "logtalk.rcompute.metrics",
757+
"command": "logtalk.check.codePortability",
744758
"when": "resourceLangId == logtalk && !virtualWorkspace",
745759
"group": "project_2@2"
746760
},
747761
{
748-
"submenu": "profilingsubmenu",
762+
"command": "logtalk.rcompute.metrics",
749763
"when": "resourceLangId == logtalk && !virtualWorkspace",
750764
"group": "project_2@3"
751765
},
766+
{
767+
"submenu": "profilingsubmenu",
768+
"when": "resourceLangId == logtalk && !virtualWorkspace",
769+
"group": "project_2@4"
770+
},
752771
{
753772
"command": "logtalk.rgenerate.diagrams",
754773
"when": "resourceLangId == logtalk && !virtualWorkspace",

src/extension.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ export async function activate(context: ExtensionContext) {
513513
{ command: "logtalk.run.test", callback: (uri, object, test) => LogtalkTerminal.runTestViaProfile(uri, object, test, linter, testsReporter, testsExplorerProvider)},
514514
{ command: "logtalk.run.doclet", callback: uri => LogtalkTerminal.runDoclet(uri, linter)},
515515
{ command: "logtalk.scan.deadCode", callback: uri => LogtalkTerminal.scanForDeadCode(uri, deadCodeScanner)},
516+
{ command: "logtalk.check.codePortability", callback: async uri => LogtalkTerminal.checkPortability(uri, linter)},
516517
{ command: "logtalk.generate.documentation", callback: uri => LogtalkTerminal.genDocumentation(uri, documentationLinter)},
517518
{ command: "logtalk.generate.diagrams", callback: uri => LogtalkTerminal.genDiagrams(uri)},
518519
{ command: "logtalk.open.parentFile", callback: uri => LogtalkTerminal.openParentFile(uri)},

src/features/terminal.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export default class LogtalkTerminal {
227227
".vscode_xml_files_done",
228228
".vscode_dot_files_done",
229229
".vscode_dead_code_scanning_done",
230+
".vscode_portability_done",
230231
".vscode_entity_definition_done",
231232
".vscode_predicate_definition_done",
232233
".vscode_declaration_done",
@@ -1735,6 +1736,58 @@ export default class LogtalkTerminal {
17351736
window.showInformationMessage("Dead code scanning completed.");
17361737
}
17371738

1739+
public static async checkPortability(uri: Uri, linter: LogtalkLinter) {
1740+
let logtalkUser: string = '';
1741+
// Check for Configurations
1742+
let section = workspace.getConfiguration("logtalk");
1743+
if (section) {
1744+
logtalkUser = jsesc(section.get<string>("user.path", "logtalk"));
1745+
} else {
1746+
throw new Error("configuration settings error: logtalk");
1747+
}
1748+
// Clear the Scratch Message File
1749+
let compilerMessagesFile = `${logtalkUser}/scratch/.messages`;
1750+
try {
1751+
await workspace.fs.delete(Uri.file(compilerMessagesFile), { useTrash: false });
1752+
} catch (err) {
1753+
// Ignore if file doesn't exist
1754+
}
1755+
// Create the Terminal
1756+
LogtalkTerminal.createLogtalkTerm();
1757+
const wdir = LogtalkTerminal.getFirstWorkspaceFolder();
1758+
if (!wdir) {
1759+
throw new Error('No workspace folder open');
1760+
}
1761+
const marker = Utils.normalizeFilePath(path.join(wdir, ".vscode_portability_done"));
1762+
let goals = `vscode::portability('${wdir}').\r`;
1763+
LogtalkTerminal.sendString(goals);
1764+
try {
1765+
await LogtalkTerminal.waitForFile(marker);
1766+
} finally {
1767+
await LogtalkTerminal.safelyDeleteFile(marker);
1768+
}
1769+
// Parse any compiler errors or warnings
1770+
try {
1771+
const content = await workspace.fs.readFile(Uri.file(compilerMessagesFile));
1772+
let lines = content.toString().split(/\r?\n/);
1773+
let message = '';
1774+
for (let line of lines) {
1775+
if (line.startsWith('% [ compiling ')) {
1776+
linter.clear(line);
1777+
} else {
1778+
message = message + line + '\n';
1779+
if(line == '* ' || line == '! ') {
1780+
linter.lint(message);
1781+
message = '';
1782+
}
1783+
}
1784+
}
1785+
} catch (err) {
1786+
// File doesn't exist or can't be read, ignore
1787+
}
1788+
window.showInformationMessage("Portability check completed.");
1789+
}
1790+
17381791
/**
17391792
* Parse tester output file and create diagnostics
17401793
*/

tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
"outDir": "out",
66
"lib": ["es6", "dom"],
77
"sourceMap": true,
8-
"rootDir": "."
8+
"rootDir": ".",
9+
"strict": false,
10+
"noImplicitAny": false,
11+
"strictNullChecks": false,
12+
"skipLibCheck": true
913
},
1014
"exclude": ["node_modules", ".vscode-test", "typings"]
1115
}

0 commit comments

Comments
 (0)