Skip to content

Commit 02c9bbe

Browse files
Merge pull request #440 from VentyCZ/master
Handle relative paths and shorthand includes
2 parents 1e72939 + e8896fd commit 02c9bbe

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"name": "Launch Client",
99
"runtimeExecutable": "${execPath}",
1010
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
11-
"outFiles": ["${workspaceRoot}/client/out/**/*.js"],
11+
"outFiles": ["${workspaceRoot}/client/dist/**/*.js"],
1212
"preLaunchTask": {
1313
"type": "npm",
1414
"script": "watch"
@@ -20,7 +20,7 @@
2020
"name": "Attach to Server",
2121
"port": 6009,
2222
"restart": true,
23-
"outFiles": ["${workspaceRoot}/server/out/**/*.js"]
23+
"outFiles": ["${workspaceRoot}/server/dist/**/*.js"]
2424
},
2525
{
2626
"name": "Language Server E2E Test",
@@ -32,7 +32,7 @@
3232
"--extensionTestsPath=${workspaceRoot}/client/out/test",
3333
"${workspaceRoot}/client/testFixture"
3434
],
35-
"outFiles": ["${workspaceRoot}/client/out/test/**/*.js"]
35+
"outFiles": ["${workspaceRoot}/client/dist/test/**/*.js"]
3636
}
3737
],
3838
"compounds": [

client/src/language/documentLink.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,43 @@ export class DocumentLinkProvider implements DocumentLinkProvider {
66
async provideDocumentLinks(document: TextDocument, token: CancellationToken) {
77
const results: DocumentLink[] = [];
88
const text: string = document.getText();
9-
const linkPattern: RegExp = /(?<=file=['"]).*\.tpl/g;
9+
const linkPattern: RegExp = /(?<=['"]).*\.tpl(?=['"])/g;
1010

1111
for (let match: RegExpExecArray; match = linkPattern.exec(text); match) {
12+
13+
// Get position in document
14+
const range = new Range(
15+
document.positionAt(match.index),
16+
document.positionAt(match.index + match[0].length)
17+
);
18+
19+
// Get target file path
20+
const fPath = match[0];
21+
22+
// Current file directory path
23+
const docdir = path.dirname(document.uri.path);
24+
25+
// Handle relative paths
26+
if (fPath.startsWith('./')) {
27+
const absPath = path.posix.resolve(docdir, fPath);
28+
29+
results.push(
30+
new DocumentLink(range, Uri.parse(absPath))
31+
);
32+
33+
continue;
34+
}
35+
1236
const uri = path.posix.normalize(match[0]?.replace(/^[/]?/, '/'));
1337

1438
const targets = await workspace.findFiles('**' + uri, null, 1);
1539

1640
// To create file if path not found
1741
if (!targets.length) {
18-
const docdir = path.dirname(document.uri.path);
1942
const pathresolved = path.posix.resolve(docdir, match[0]?.replace(/^[/]?/, ''));
2043
targets.push(Uri.parse(pathresolved));
2144
}
2245

23-
const range = new Range(
24-
document.positionAt(match.index),
25-
document.positionAt(match.index + match[0].length)
26-
);
2746
const doumentlink = new DocumentLink(range, targets[0]);
2847

2948
results.push(doumentlink);

extension.webpack.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ const path = require('path');
1313
const browserClientConfig = {
1414
context: path.join(__dirname, 'client'),
1515
mode: 'none',
16-
target: 'node', // vscode extensions run in a node context
16+
devtool: 'nosources-source-map',
17+
target: 'node', // vscode extensions run in a node context
1718
entry: {
1819
nodeClientMain: './src/extension.ts',
1920
},
2021
output: {
2122
filename: '[name].js',
2223
path: path.join(__dirname, 'client', 'dist', 'node'),
2324
libraryTarget: 'commonjs',
25+
devtoolModuleFilenameTemplate: '[absolute-resource-path]'
2426
},
2527
resolve: {
2628
extensions: ['.ts', '.js'], // support ts-files and js-files
@@ -47,7 +49,7 @@ const browserClientConfig = {
4749
const browserServerConfig = {
4850
context: path.join(__dirname, 'server'),
4951
mode: 'none',
50-
target: 'node', // vscode extensions run in a node context
52+
target: 'node', // vscode extensions run in a node context
5153
entry: {
5254
nodeServerMain: './src/node/htmlServerMain.ts',
5355
},

0 commit comments

Comments
 (0)