File tree Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 1
- import { EOL } from 'os' ;
2
1
import { CompletionItem , type Position } from 'vscode-languageserver-protocol' ;
3
2
import type { TextDocument } from 'vscode-languageserver-textdocument' ;
4
3
import * as lsp from 'vscode-languageserver/node' ;
7
6
findImportPath ,
8
7
getAllClassNames ,
9
8
getCurrentDirFromUri ,
9
+ getEOL ,
10
10
getTransformer ,
11
11
} from './utils' ;
12
12
import type { CamelCaseValues } from './utils' ;
@@ -170,7 +170,7 @@ export class CSSModulesCompletionProvider {
170
170
position : Position ,
171
171
) : Promise < CompletionItem [ ] | null > {
172
172
const fileContent = textdocument . getText ( ) ;
173
- const lines = fileContent . split ( EOL ) ;
173
+ const lines = fileContent . split ( getEOL ( fileContent ) ) ;
174
174
const currentLine = lines [ position . line ] ;
175
175
if ( typeof currentLine !== 'string' ) return null ;
176
176
const currentDir = getCurrentDirFromUri ( textdocument . uri ) ;
Original file line number Diff line number Diff line change 1
- import { EOL } from 'os' ;
2
1
import path from 'path' ;
3
2
import {
4
3
type Hover ,
@@ -16,6 +15,7 @@ import {
16
15
findImportPath ,
17
16
genImportRegExp ,
18
17
getCurrentDirFromUri ,
18
+ getEOL ,
19
19
getPosition ,
20
20
getTransformer ,
21
21
getWords ,
@@ -57,6 +57,7 @@ export class CSSModulesDefinitionProvider {
57
57
position : Position ,
58
58
) : Promise < null | Hover > {
59
59
const fileContent = textdocument . getText ( ) ;
60
+ const EOL = getEOL ( fileContent ) ;
60
61
const lines = fileContent . split ( EOL ) ;
61
62
const currentLine = lines [ position . line ] ;
62
63
@@ -93,6 +94,7 @@ export class CSSModulesDefinitionProvider {
93
94
field ,
94
95
node . declarations ,
95
96
node . comments ,
97
+ EOL ,
96
98
) ,
97
99
} ,
98
100
} ;
@@ -103,7 +105,7 @@ export class CSSModulesDefinitionProvider {
103
105
position : Position ,
104
106
) : Promise < Location | null > {
105
107
const fileContent = textdocument . getText ( ) ;
106
- const lines = fileContent . split ( EOL ) ;
108
+ const lines = fileContent . split ( getEOL ( fileContent ) ) ;
107
109
const currentLine = lines [ position . line ] ;
108
110
109
111
if ( typeof currentLine !== 'string' ) {
Original file line number Diff line number Diff line change 1
1
import fs from 'fs' ;
2
- import { EOL } from 'os' ;
3
2
import path from 'path' ;
4
3
import url from 'url' ;
5
4
import _camelCase from 'lodash.camelcase' ;
@@ -266,6 +265,7 @@ export async function filePathToClassnameDict(
266
265
classnameTransformer : StringTransformer ,
267
266
) : Promise < ClassnameDict > {
268
267
const content = fs . readFileSync ( filepath , { encoding : 'utf8' } ) ;
268
+ const EOL = getEOL ( content ) ;
269
269
const { ext} = path . parse ( filepath ) ;
270
270
271
271
/**
@@ -427,6 +427,7 @@ export function stringifyClassname(
427
427
classname : string ,
428
428
declarations : string [ ] ,
429
429
comments : string [ ] ,
430
+ EOL : string ,
430
431
) : string {
431
432
const commentString = comments . length
432
433
? comments
@@ -452,3 +453,20 @@ export function stringifyClassname(
452
453
] . join ( EOL )
453
454
) ;
454
455
}
456
+
457
+ // https://github.com/wkillerud/some-sass/blob/main/vscode-extension/src/utils/string.ts
458
+ export function getEOL ( text : string ) : string {
459
+ for ( let i = 0 ; i < text . length ; i ++ ) {
460
+ const ch = text . charAt ( i ) ;
461
+ if ( ch === '\r' ) {
462
+ if ( i + 1 < text . length && text . charAt ( i + 1 ) === '\n' ) {
463
+ return '\r\n' ;
464
+ }
465
+ return '\r' ;
466
+ }
467
+ if ( ch === '\n' ) {
468
+ return '\n' ;
469
+ }
470
+ }
471
+ return '\n' ;
472
+ }
You can’t perform that action at this time.
0 commit comments