File tree 3 files changed +21
-37
lines changed
packages/@css-blocks/language-server/src
3 files changed +21
-37
lines changed Original file line number Diff line number Diff line change @@ -52,16 +52,17 @@ export class Server {
52
52
53
53
async onDidChangeContent ( e : TextDocumentChangeEvent ) {
54
54
// only track incremental changes within block files
55
- // NOTE: this does seem to cause a little bit of weirdness when editing a
56
- // template with errors since the error locations do not get updated until
57
- // saving the file. We may want to validate the open template files on
58
- // every change?
55
+ this . blockFactory . reset ( ) ;
59
56
if ( isBlockFile ( e . document . uri ) ) {
60
- const cssBlockErrors = await documentContentChange ( e , this . blockParser ) ;
57
+ const cssBlockErrors = await documentContentChange ( e , this . blockFactory ) ;
61
58
this . sendDiagnostics ( cssBlockErrors , e . document . uri ) ;
62
59
63
60
} else if ( isTemplateFile ( e . document . uri ) ) {
64
61
// Validate template
62
+ // NOTE: this does seem to cause a little bit of weirdness when editing a
63
+ // template with errors since the error locations do not get updated until
64
+ // saving the file. We may want to validate the open template files on
65
+ // every change?
65
66
}
66
67
67
68
}
Original file line number Diff line number Diff line change 1
- import { CssBlockError } from "@css-blocks/core/dist/src" ;
2
- import { BlockParser } from "@css-blocks/core/dist/src/BlockParser/BlockParser" ;
1
+ import { BlockFactory , CssBlockError } from "@css-blocks/core/dist/src" ;
3
2
import { TextDocumentChangeEvent } from "vscode-languageserver" ;
4
3
import { URI } from "vscode-uri" ;
5
4
6
- import { isBlockFile , parseBlockErrors } from "../util/blockUtils" ;
5
+ import { isBlockFile } from "../util/blockUtils" ;
7
6
8
- export async function documentContentChange ( e : TextDocumentChangeEvent , parser : BlockParser ) : Promise < CssBlockError [ ] > {
7
+ export async function documentContentChange ( e : TextDocumentChangeEvent , blockFactory : BlockFactory ) : Promise < CssBlockError [ ] > {
9
8
const { uri } = e . document ;
10
9
11
10
if ( isBlockFile ( uri ) ) {
12
- return await parseBlockErrors ( parser , URI . parse ( uri ) . fsPath , e . document . getText ( ) ) ;
11
+ let errors : CssBlockError [ ] = [ ] ;
12
+ try {
13
+ // parses the block file to get the block and errors if there's a problem
14
+ // along the way. The importer ensures that we're getting live contents if
15
+ // the block file is opened
16
+ await blockFactory . getBlockFromPath ( URI . parse ( uri ) . fsPath ) ;
17
+ } catch ( error ) {
18
+ if ( error instanceof CssBlockError ) {
19
+ errors = errors . concat ( error ) ;
20
+ }
21
+ return errors ;
22
+ }
13
23
}
14
-
15
24
return [ ] ;
16
25
}
Original file line number Diff line number Diff line change 1
- import { CssBlockError , Syntax } from "@css-blocks/core/dist/src" ;
2
- import { BlockParser } from "@css-blocks/core/dist/src/BlockParser/BlockParser" ;
3
- import { postcss } from "opticss" ;
4
- import * as path from "path" ;
5
-
6
1
// TODO: Currently we are only supporting css. This should eventually support all
7
2
// of the file types supported by css blocks
8
3
export function isBlockFile ( uriOrFsPath : string ) {
9
4
return uriOrFsPath . endsWith ( ".block.css" ) ;
10
5
}
11
-
12
- export async function parseBlockErrors ( parser : BlockParser , blockFsPath : string , sourceText : string ) : Promise < CssBlockError [ ] > {
13
- let errors : CssBlockError [ ] = [ ] ;
14
-
15
- try {
16
- await parser . parseSource ( {
17
- identifier : blockFsPath ,
18
- defaultName : path . parse ( blockFsPath ) . name . replace ( / \. b l o c k / , "" ) ,
19
- originalSource : sourceText ,
20
- originalSyntax : Syntax . css ,
21
- parseResult : postcss . parse ( sourceText , { from : blockFsPath } ) ,
22
- dependencies : [ ] ,
23
- } ) ;
24
- } catch ( error ) {
25
- if ( error instanceof CssBlockError ) {
26
- errors = errors . concat ( error ) ;
27
- }
28
- }
29
-
30
- return errors ;
31
- }
You can’t perform that action at this time.
0 commit comments