Skip to content

Commit e4d3ca9

Browse files
committed
Get tests green
1 parent a787a13 commit e4d3ca9

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

extensions/html-language-features/server/src/modes/javascriptMode.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { normalize, sep } from 'path';
1616

1717
import * as ts from 'typescript';
1818
import { getSemanticTokens, getSemanticTokenLegend } from './javascriptSemanticTokens';
19-
import { RequestService } from '../requests';
19+
import { FileSystemProvider } from '../requests';
2020
import { NodeRequestService } from '../node/nodeFs';
2121

2222
const JS_WORD_REGEX = /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g;
@@ -33,7 +33,7 @@ function deschemeURI(uri: string) {
3333
// Both \ and / must be escaped in regular expressions
3434
newPath = newPath.replace(new RegExp('\\' + sep, 'g'), '/');
3535

36-
if (process.platform !== 'win32') return newPath;
36+
if (process.platform !== 'win32') { return newPath; }
3737

3838
// Windows URIs come in like '/c%3A/Users/orta/dev/...', we need to switch it to 'c:/Users/orta/dev/...'
3939
return newPath.slice(1).replace('%3A', ':');
@@ -104,7 +104,9 @@ function getLanguageServiceHost(scriptKind: ts.ScriptKind, fs: NodeRequestServic
104104
return {
105105
async getLanguageService(jsDocument: TextDocument, workspace: Workspace): Promise<ts.LanguageService> {
106106
currentTextDocument = jsDocument;
107-
if (workspace.folders.find(f => f.uri.startsWith('file://'))) currentWorkspace = workspace;
107+
if (workspace.folders.find(f => f.uri.startsWith('file://') || f.uri.startsWith('/') || f.uri.startsWith('\\'))) {
108+
currentWorkspace = workspace;
109+
}
108110
return jsLanguageService;
109111
},
110112
getCompilationSettings() {
@@ -117,7 +119,7 @@ function getLanguageServiceHost(scriptKind: ts.ScriptKind, fs: NodeRequestServic
117119
}
118120

119121

120-
export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocumentRegions>, languageId: 'javascript' | 'typescript', workspace: Workspace, fs: RequestService): LanguageMode {
122+
export function getJavaScriptMode(documentRegions: LanguageModelCache<HTMLDocumentRegions>, languageId: 'javascript' | 'typescript', workspace: Workspace, fs: FileSystemProvider): LanguageMode {
121123
let jsDocuments = getLanguageModelCache<TextDocument>(10, 60, document => documentRegions.get(document).getEmbeddedDocument(languageId));
122124

123125
const host = getLanguageServiceHost(languageId === 'javascript' ? ts.ScriptKind.JS : ts.ScriptKind.TS, fs as NodeRequestService);

extensions/html-language-features/server/src/node/nodeFs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export interface NodeRequestService extends FileSystemProvider {
1818
statSync(location: string): FileStat
1919
}
2020

21-
export function getNodeFSRequestService(): NodeRequestService {
21+
export function getNodeFileFS(): NodeRequestService {
2222
function ensureFileUri(location: string) {
23-
if (getScheme(location) !== 'file') {
24-
throw new Error('fileSystemProvider can only handle file URLs');
23+
if (getScheme(location) !== 'file' && getScheme(location) !== '') {
24+
throw new Error(`fileSystemProvider can only handle file URLs, got ${getScheme(location)}`);
2525
}
2626
}
2727

extensions/html-language-features/server/src/test/completions.test.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,25 @@ suite('HTML Completion', () => {
9494
});
9595
});
9696

97-
suite('JSDoc Imports', () => {
97+
suite('Live TSServer inside the HTML script tags', () => {
9898
const fixtureRoot = path.resolve(__dirname, '../../src/test/jsdocImportFixtures');
9999
const fixtureWorkspace = { name: 'fixture', uri: URI.file(fixtureRoot).toString() };
100100
const indexHtmlUri = URI.file(path.resolve(fixtureRoot, 'index.html')).toString();
101101

102-
test('Imports across files', async () => {
102+
test('Imports across files when using fixtured data from the file system', async () => {
103103
await testCompletionFor('<html><script>/** @type {import("./jsDocTypes").SomeType } */\nconst a = {}; \n a.| \n</script><html>', {
104104
items: [
105-
{ label: 'other', },
106-
{ label: 'property', },
105+
{ label: 'other' },
106+
{ label: 'property' },
107107
]
108-
}, indexHtmlUri, [fixtureWorkspace] );
108+
}, indexHtmlUri, [fixtureWorkspace]);
109+
});
110+
111+
test('Does not run the extended tsserver when _not_ using the local file system', async () => {
112+
await testCompletionFor('<html><script>/** @type {import("./jsDocTypes").SomeType } */\nconst a {};\n a.|</script></html>', {
113+
// As it's an 'any' then it has no completions
114+
items: []
115+
}, 'vfs://index.html', [{ name: 'vfs', uri: 'vfs://' }]);
109116
});
110117
});
111118

0 commit comments

Comments
 (0)