diff --git a/src/core/file-system.ts b/src/core/file-system.ts deleted file mode 100644 index 45053116b..000000000 --- a/src/core/file-system.ts +++ /dev/null @@ -1,21 +0,0 @@ -import * as vscode from 'vscode' -import * as fs from 'fs' - -export class LwFileSystem { - isLocalUri(uri: vscode.Uri): boolean { - return uri.scheme === 'file' - } - - isVirtualUri(uri: vscode.Uri): boolean { - return !this.isLocalUri(uri) - } - - async readFileAsBuffer(fileUri: vscode.Uri): Promise { - if (this.isLocalUri(fileUri)) { - return fs.promises.readFile(fileUri.fsPath) - } else { - const resultUint8 = await vscode.workspace.fs.readFile(fileUri) - return Buffer.from(resultUint8) - } - } -} diff --git a/src/language/definition.ts b/src/language/definition.ts index d0c04e31d..273158b00 100644 --- a/src/language/definition.ts +++ b/src/language/definition.ts @@ -41,7 +41,7 @@ export class DefinitionProvider implements vscode.DefinitionProvider { } provideDefinition(document: vscode.TextDocument, position: vscode.Position): vscode.Location | undefined { - if (lw.lwfs.isVirtualUri(document.uri)) { + if (document.uri.scheme !== 'file') { return } const token = tokenizer(document, position) diff --git a/src/language/symbol-document.ts b/src/language/symbol-document.ts index cddac5226..c388ff520 100644 --- a/src/language/symbol-document.ts +++ b/src/language/symbol-document.ts @@ -1,5 +1,4 @@ import * as vscode from 'vscode' -import { lw } from '../lw' import { TeXElement, TeXElementType } from '../outline/structurelib/types' import { buildBibTeX } from '../outline/structurelib/bibtex' import { construct as constructLaTeX } from '../outline/structurelib/latex' @@ -13,7 +12,7 @@ export class DocSymbolProvider implements vscode.DocumentSymbolProvider { } else if (document.languageId === 'doctex') { return construct(document).then((sections: TeXElement[]) => this.sectionToSymbols(sections)) } - if (lw.lwfs.isVirtualUri(document.uri)) { + if (document.uri.scheme !== 'file') { return [] } const sections = await constructLaTeX(document.fileName, false) diff --git a/src/lw.ts b/src/lw.ts index a0eaf449a..6807a7404 100644 --- a/src/lw.ts +++ b/src/lw.ts @@ -13,7 +13,6 @@ import type { Cleaner } from './extras/cleaner' import type { LaTeXCommanderTreeView } from './extras/activity-bar' import type { Counter } from './extras/counter' import type { Linter } from './lint/latex-linter' -import type { LwFileSystem } from './core/file-system' import type { MathPreviewPanel } from './extras/math-preview-panel' import type { Section } from './extras/section' import type { dupLabelDetector } from './lint/duplicate-label' @@ -38,7 +37,6 @@ export const lw = { cache: {} as typeof cache, root: {} as typeof root, compile: {} as typeof compile, - lwfs: Object.create(null) as LwFileSystem, viewer: {} as typeof viewer, server: {} as typeof server, locate: {} as typeof locate, diff --git a/src/main.ts b/src/main.ts index ce0ade89b..cb943f512 100644 --- a/src/main.ts +++ b/src/main.ts @@ -38,7 +38,6 @@ import { LaTeXCommanderTreeView } from './extras/activity-bar' import { Counter } from './extras/counter' import { dupLabelDetector } from './lint/duplicate-label' import { Linter } from './lint/latex-linter' -import { LwFileSystem } from './core/file-system' import { MathPreviewPanel } from './extras/math-preview-panel' import { Section } from './extras/section' import { SnippetView } from './extras/snippet-view' @@ -57,7 +56,6 @@ const logger = lw.log('Extension') function initialize(extensionContext: vscode.ExtensionContext) { lw.onDispose(undefined, extensionContext.subscriptions) - lw.lwfs = new LwFileSystem() lw.completer = new Completer() lw.atSuggestionCompleter = new AtSuggestionCompleter() lw.linter = new Linter() @@ -113,7 +111,7 @@ export function activate(extensionContext: vscode.ExtensionContext) { })) extensionContext.subscriptions.push(vscode.workspace.onDidSaveTextDocument( (e: vscode.TextDocument) => { - if (lw.lwfs.isVirtualUri(e.uri)){ + if (e.uri.scheme !== 'file'){ return } if (lw.file.hasTexLangId(e.languageId) || @@ -141,7 +139,7 @@ export function activate(extensionContext: vscode.ExtensionContext) { } else if (vscode.window.activeTextEditor && vscode.window.activeTextEditor.document.languageId.toLowerCase() === 'log') { logger.showStatus() } - if (e && lw.lwfs.isVirtualUri(e.document.uri)){ + if (e && e.document.uri.scheme !== 'file'){ return } if (e && lw.file.hasTexLangId(e.document.languageId) && e.document.fileName !== prevTeXDocumentPath) { @@ -154,7 +152,7 @@ export function activate(extensionContext: vscode.ExtensionContext) { })) extensionContext.subscriptions.push(vscode.workspace.onDidChangeTextDocument((e: vscode.TextDocumentChangeEvent) => { - if (lw.lwfs.isVirtualUri(e.document.uri)){ + if (e.document.uri.scheme !== 'file'){ return } if (!lw.file.hasTexLangId(e.document.languageId) && diff --git a/src/preview/server.ts b/src/preview/server.ts index 2fb69f10f..014dea076 100644 --- a/src/preview/server.ts +++ b/src/preview/server.ts @@ -193,7 +193,7 @@ async function handler(request: http.IncomingMessage, response: http.ServerRespo return } try { - const buf: Buffer = await lw.lwfs.readFileAsBuffer(fileUri) + const buf: Buffer = Buffer.from(await vscode.workspace.fs.readFile(fileUri)) sendOkResponse(response, buf, 'application/pdf') logger.log(`Preview PDF file: ${fileUri.toString(true)}`) } catch (e) {