Skip to content

Commit 6331ccb

Browse files
authored
(fix) no diagnostics for coffeescript (#780)
1 parent 0119c09 commit 6331ccb

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

packages/language-server/src/lib/documents/Document.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ export class Document extends WritableDocument {
6262
return this.url;
6363
}
6464

65+
/**
66+
* Returns the language associated to either script or style.
67+
* Returns an empty string if there's nothing set.
68+
*/
69+
getLanguageAttribute(tag: 'script' | 'style'): string {
70+
const attrs =
71+
(tag === 'style'
72+
? this.styleInfo?.attributes
73+
: this.scriptInfo?.attributes || this.moduleScriptInfo?.attributes) || {};
74+
const lang = attrs.lang || attrs.type || '';
75+
return lang.replace(/^text\//, '');
76+
}
77+
6578
private addDefaultLanguage(
6679
tagInfo: TagInformation | null,
6780
tag: 'style' | 'script'

packages/language-server/src/plugins/typescript/features/DiagnosticsProvider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ export class DiagnosticsProviderImpl implements DiagnosticsProvider {
1111

1212
async getDiagnostics(document: Document): Promise<Diagnostic[]> {
1313
const { lang, tsDoc } = this.getLSAndTSDoc(document);
14+
15+
if (['coffee', 'coffeescript'].includes(document.getLanguageAttribute('script'))) {
16+
return [];
17+
}
18+
1419
const isTypescript = tsDoc.scriptKind === ts.ScriptKind.TSX;
1520

1621
// Document preprocessing failed, show parser error instead

packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,11 @@ describe('DiagnosticsProvider', () => {
258258
}
259259
]);
260260
});
261+
262+
it('ignores coffeescript', async () => {
263+
const { plugin, document } = setup('diagnostics-coffeescript.svelte');
264+
const diagnostics = await plugin.getDiagnostics(document);
265+
266+
assert.deepStrictEqual(diagnostics, []);
267+
});
261268
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script lang="coffee">
2+
# Assignment:
3+
number = 42
4+
opposite = true
5+
6+
# Conditions:
7+
number = -42 if opposite
8+
9+
# Functions:
10+
square = (x) -> x * x
11+
12+
# Arrays:
13+
list = [1, 2, 3, 4, 5]
14+
15+
# Objects:
16+
math =
17+
root: Math.sqrt
18+
square: square
19+
cube: (x) -> x * square x
20+
21+
# Splats:
22+
race = (winner, runners...) ->
23+
print winner, runners
24+
25+
# Existence:
26+
alert "I knew it!" if elvis?
27+
28+
# Array comprehensions:
29+
cubes = (math.cube num for num in list)
30+
</script>

0 commit comments

Comments
 (0)