Skip to content

Commit fa77294

Browse files
committed
Update local path resolution
1 parent 2e48261 commit fa77294

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

README.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,29 @@ Missing CSS support for HTML documents.
1111

1212
## Example
1313

14-
In the following HTML file, completion will suggest for all `id` and `class` attributes.
14+
In the following HTML file, completion will suggest for all `id` and `class` attributes. All
15+
local links point to `site.css`.
1516

1617
**`index.html`**
1718
```html
1819
<!DOCTYPE html>
1920
<html>
2021

2122
<head>
22-
<!-- (1) -->
23-
<link
24-
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
25-
rel="stylesheet">
23+
<!-- (1) Remote style sheet -->
24+
<link rel="stylesheet"
25+
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
2626

27-
<!-- (2) -->
28-
<link href="site.css" rel="stylesheet">
29-
<link href="./site.css" rel="stylesheet">
30-
<link href="/site.css" rel="stylesheet">
27+
<!-- (2) Local style sheet relative to workspace folder -->
28+
<link rel="stylesheet" href="/site.css">
3129

32-
<!-- (3) -->
30+
<!-- (3) Local style sheet relative to this file -->
31+
<link rel="stylesheet" href="site.css">
32+
33+
<!-- (4) Local style sheet relative to this file -->
34+
<link rel="stylesheet" href="./site.css">
35+
36+
<!-- (5) Embedded style sheet -->
3337
<style>
3438
#content {
3539
display: block;
@@ -52,9 +56,6 @@ In the following HTML file, completion will suggest for all `id` and `class` att
5256

5357
</html>
5458
```
55-
1. External style sheet which will be fetched from `href`.
56-
2. Local style sheets which are all equivalent and points to `site.css` file in the root of workspace folder.
57-
3. Embedded style tag.
5859

5960
**`site.css`**
6061
```css
@@ -73,9 +74,13 @@ If it is not possible to specify local or remote styles within each HTML file, t
7374
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
7475

7576
// (2)
77+
"/site.css",
78+
79+
// (3)
7680
"site.css",
77-
"./site.css",
78-
"/site.css"
81+
82+
// (4)
83+
"./site.css"
7984
]
8085
```
8186

@@ -94,7 +99,8 @@ Extension can be configured to support any language where it makes sense such as
9499
`php`, `javascriptreact`, `nunjucks` etc. You should install corresponding language extension
95100
which registers choosen language id in VS Code.
96101

97-
This setting is application scoped so it should be set in global settings.
102+
This setting is application scoped so it should be set in global settings and changes requires
103+
restarting VS Code.
98104

99105
## Installation
100106

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-html-css",
33
"displayName": "HTML CSS Support",
44
"description": "CSS support for HTML documents",
5-
"version": "1.2.2",
5+
"version": "1.2.3",
66
"publisher": "ecmel",
77
"license": "MIT",
88
"homepage": "https://github.com/ecmel/vscode-html-css",

src/extension.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fetch from "node-fetch";
2+
import { isAbsolute, join, dirname } from "path";
23
import { parse, walk } from "css-tree";
34
import {
45
CancellationToken,
@@ -69,7 +70,12 @@ export class ClassCompletionItemProvider implements CompletionItemProvider, Disp
6970
resolve(key);
7071
} else {
7172
const folder = workspace.getWorkspaceFolder(uri);
72-
const file = folder ? Uri.joinPath(folder.uri, key) : Uri.file(key);
73+
74+
const file = Uri.file(folder
75+
? join(isAbsolute(key)
76+
? folder.uri.fsPath
77+
: dirname(uri.fsPath), key)
78+
: key);
7379

7480
workspace.fs.readFile(file).then(content => {
7581
const items = new Map<string, CompletionItem>();

0 commit comments

Comments
 (0)