@vuedx/vue-virtual-textdocument
Advanced tools
Comparing version 0.1.0-alpha.2 to 0.1.0-alpha.3
@@ -18,3 +18,4 @@ import { SFCDescriptor, SFCBlock, CompilerError } from '@vuedx/compiler-sfc'; | ||
readonly container: VueTextDocument; | ||
constructor(internal: TextDocument, container: VueTextDocument); | ||
readonly selector: BlockSelector; | ||
constructor(internal: TextDocument, container: VueTextDocument, selector: BlockSelector); | ||
readonly uriObject: URI; | ||
@@ -36,3 +37,3 @@ get version(): number; | ||
}; | ||
static create(container: VueTextDocument, uri: string, languageId: string, version: number, content: string): VirtualTextDocument; | ||
static create(container: VueTextDocument, uri: string, languageId: string, version: number, content: string, selector: BlockSelector): VirtualTextDocument; | ||
static update(document: VirtualTextDocument, changes: TextDocumentContentChangeEvent[], version: number): VirtualTextDocument; | ||
@@ -61,2 +62,3 @@ } | ||
blockAt(positionOrOffset: Position | number): SFCBlock | undefined; | ||
documentAt(positionOrOffset: Position | number): VirtualTextDocument | null | undefined; | ||
private parse; | ||
@@ -80,7 +82,8 @@ private createBlockDocument; | ||
declare class DocumentStore<T> { | ||
private resolve; | ||
private map; | ||
private lowerCaseNames; | ||
constructor(resolve: (uri: string) => T | null); | ||
private normalizeUri; | ||
protected resolve: (uri: string) => T | null; | ||
normalize: (uri: string) => string; | ||
protected map: Map<string, T>; | ||
protected reverseUriMap: Map<string, string>; | ||
constructor(resolve: (uri: string) => T | null, normalize?: (uri: string) => string); | ||
protected getNormalizedUri(uri: string): string; | ||
has(uri: string): boolean; | ||
@@ -94,14 +97,6 @@ get(uri: string): T | null; | ||
} | ||
declare class AsyncDocumentStore<T> { | ||
private resolve; | ||
private useCaseSensitiveFileNames; | ||
private map; | ||
constructor(resolve: (uri: string) => Promise<T | null> | T | null, useCaseSensitiveFileNames?: () => boolean); | ||
private normalizeUri; | ||
has(uri: string): boolean; | ||
get(uri: string): T | Promise<T | null>; | ||
set(uri: string, document: T): void; | ||
delete(uri: string): boolean; | ||
all(): string[]; | ||
dispose(): void; | ||
declare class AsyncDocumentStore<T> extends DocumentStore<T> { | ||
constructor(resolve: (uri: string) => T | Promise<T | null> | null, normalize?: (uri: string) => string); | ||
get(uri: string): T | null; | ||
get(uri: string): Promise<T | null>; | ||
private load; | ||
@@ -108,0 +103,0 @@ } |
@@ -24,5 +24,6 @@ import { parse } from '@vuedx/compiler-sfc'; | ||
class VirtualTextDocument { | ||
constructor(internal, container) { | ||
constructor(internal, container, selector) { | ||
this.internal = internal; | ||
this.container = container; | ||
this.selector = selector; | ||
this.uriObject = URI.parse(this.internal.uri); | ||
@@ -65,4 +66,4 @@ } | ||
} | ||
static create(container, uri, languageId, version, content) { | ||
return new VirtualTextDocument(TextDocument.create(uri, languageId, version, content), container); | ||
static create(container, uri, languageId, version, content, selector) { | ||
return new VirtualTextDocument(TextDocument.create(uri, languageId, version, content), container, selector); | ||
} | ||
@@ -131,2 +132,6 @@ static update(document, changes, version) { | ||
} | ||
documentAt(positionOrOffset) { | ||
const block = this.blockAt(positionOrOffset); | ||
return block ? this.getBlockDocument(block) : undefined; | ||
} | ||
parse() { | ||
@@ -168,3 +173,4 @@ const source = this.getText(); | ||
return null; | ||
const id = stringify(this.getSelectorFor(block)); | ||
const selector = this.getSelectorFor(block); | ||
const id = stringify(selector); | ||
const uri = this.getUriFor(block); | ||
@@ -178,3 +184,3 @@ const languageId = getLanguageIdForBlock(block); | ||
} | ||
return VirtualTextDocument.create(this, uri, languageId, this.version, block.content); | ||
return VirtualTextDocument.create(this, uri, languageId, this.version, block.content, selector); | ||
} | ||
@@ -302,23 +308,23 @@ all() { | ||
class DocumentStore { | ||
constructor(resolve) { | ||
constructor(resolve, normalize = (uri) => uri) { | ||
this.resolve = resolve; | ||
this.normalize = normalize; | ||
this.map = new Map(); | ||
this.lowerCaseNames = new Map(); | ||
this.reverseUriMap = new Map(); | ||
} | ||
normalizeUri(uri) { | ||
const lower = uri.toLowerCase(); | ||
return this.lowerCaseNames.get(lower) || uri; | ||
getNormalizedUri(uri) { | ||
return this.reverseUriMap.get(this.normalize(uri)) || uri; | ||
} | ||
has(uri) { | ||
return this.map.has(this.normalizeUri(uri)); | ||
return this.map.has(this.getNormalizedUri(uri)); | ||
} | ||
get(uri) { | ||
return this.map.get(this.normalizeUri(uri)) || this.loadSync(uri); | ||
return this.map.get(this.getNormalizedUri(uri)) || this.loadSync(uri); | ||
} | ||
set(uri, document) { | ||
this.map.set(uri, document); | ||
this.lowerCaseNames.set(uri.toLowerCase(), uri); | ||
this.reverseUriMap.set(uri.toLowerCase(), uri); | ||
} | ||
delete(uri) { | ||
return this.map.delete(this.normalizeUri(uri)); | ||
return this.map.delete(this.getNormalizedUri(uri)); | ||
} | ||
@@ -339,33 +345,13 @@ all() { | ||
} | ||
class AsyncDocumentStore { | ||
constructor(resolve, useCaseSensitiveFileNames = () => true) { | ||
this.resolve = resolve; | ||
this.useCaseSensitiveFileNames = useCaseSensitiveFileNames; | ||
this.map = new Map(); | ||
class AsyncDocumentStore extends DocumentStore { | ||
constructor(resolve, normalize = (uri) => uri) { | ||
super(resolve, normalize); | ||
} | ||
normalizeUri(uri) { | ||
return this.useCaseSensitiveFileNames() ? uri : uri.toLowerCase(); | ||
} | ||
has(uri) { | ||
return this.map.has(this.normalizeUri(uri)); | ||
} | ||
get(uri) { | ||
return this.map.get(this.normalizeUri(uri)) || this.load(uri); | ||
return this.map.get(this.getNormalizedUri(uri)) || this.load(uri); | ||
} | ||
set(uri, document) { | ||
this.map.set(this.normalizeUri(uri), document); | ||
} | ||
delete(uri) { | ||
return this.map.delete(this.normalizeUri(uri)); | ||
} | ||
all() { | ||
return Array.from(this.map.keys()); | ||
} | ||
dispose() { | ||
this.map.clear(); | ||
} | ||
async load(uri) { | ||
const document = await this.resolve(uri); | ||
if (document) { | ||
this.map.set(this.normalizeUri(uri), document); | ||
this.map.set(this.getNormalizedUri(uri), document); | ||
} | ||
@@ -372,0 +358,0 @@ return document; |
@@ -28,5 +28,6 @@ 'use strict'; | ||
class VirtualTextDocument { | ||
constructor(internal, container) { | ||
constructor(internal, container, selector) { | ||
this.internal = internal; | ||
this.container = container; | ||
this.selector = selector; | ||
this.uriObject = vscodeUri.URI.parse(this.internal.uri); | ||
@@ -69,4 +70,4 @@ } | ||
} | ||
static create(container, uri, languageId, version, content) { | ||
return new VirtualTextDocument(vscodeLanguageserverTextdocument.TextDocument.create(uri, languageId, version, content), container); | ||
static create(container, uri, languageId, version, content, selector) { | ||
return new VirtualTextDocument(vscodeLanguageserverTextdocument.TextDocument.create(uri, languageId, version, content), container, selector); | ||
} | ||
@@ -135,2 +136,6 @@ static update(document, changes, version) { | ||
} | ||
documentAt(positionOrOffset) { | ||
const block = this.blockAt(positionOrOffset); | ||
return block ? this.getBlockDocument(block) : undefined; | ||
} | ||
parse() { | ||
@@ -172,3 +177,4 @@ const source = this.getText(); | ||
return null; | ||
const id = querystring.stringify(this.getSelectorFor(block)); | ||
const selector = this.getSelectorFor(block); | ||
const id = querystring.stringify(selector); | ||
const uri = this.getUriFor(block); | ||
@@ -182,3 +188,3 @@ const languageId = getLanguageIdForBlock(block); | ||
} | ||
return VirtualTextDocument.create(this, uri, languageId, this.version, block.content); | ||
return VirtualTextDocument.create(this, uri, languageId, this.version, block.content, selector); | ||
} | ||
@@ -306,23 +312,23 @@ all() { | ||
class DocumentStore { | ||
constructor(resolve) { | ||
constructor(resolve, normalize = (uri) => uri) { | ||
this.resolve = resolve; | ||
this.normalize = normalize; | ||
this.map = new Map(); | ||
this.lowerCaseNames = new Map(); | ||
this.reverseUriMap = new Map(); | ||
} | ||
normalizeUri(uri) { | ||
const lower = uri.toLowerCase(); | ||
return this.lowerCaseNames.get(lower) || uri; | ||
getNormalizedUri(uri) { | ||
return this.reverseUriMap.get(this.normalize(uri)) || uri; | ||
} | ||
has(uri) { | ||
return this.map.has(this.normalizeUri(uri)); | ||
return this.map.has(this.getNormalizedUri(uri)); | ||
} | ||
get(uri) { | ||
return this.map.get(this.normalizeUri(uri)) || this.loadSync(uri); | ||
return this.map.get(this.getNormalizedUri(uri)) || this.loadSync(uri); | ||
} | ||
set(uri, document) { | ||
this.map.set(uri, document); | ||
this.lowerCaseNames.set(uri.toLowerCase(), uri); | ||
this.reverseUriMap.set(uri.toLowerCase(), uri); | ||
} | ||
delete(uri) { | ||
return this.map.delete(this.normalizeUri(uri)); | ||
return this.map.delete(this.getNormalizedUri(uri)); | ||
} | ||
@@ -343,33 +349,13 @@ all() { | ||
} | ||
class AsyncDocumentStore { | ||
constructor(resolve, useCaseSensitiveFileNames = () => true) { | ||
this.resolve = resolve; | ||
this.useCaseSensitiveFileNames = useCaseSensitiveFileNames; | ||
this.map = new Map(); | ||
class AsyncDocumentStore extends DocumentStore { | ||
constructor(resolve, normalize = (uri) => uri) { | ||
super(resolve, normalize); | ||
} | ||
normalizeUri(uri) { | ||
return this.useCaseSensitiveFileNames() ? uri : uri.toLowerCase(); | ||
} | ||
has(uri) { | ||
return this.map.has(this.normalizeUri(uri)); | ||
} | ||
get(uri) { | ||
return this.map.get(this.normalizeUri(uri)) || this.load(uri); | ||
return this.map.get(this.getNormalizedUri(uri)) || this.load(uri); | ||
} | ||
set(uri, document) { | ||
this.map.set(this.normalizeUri(uri), document); | ||
} | ||
delete(uri) { | ||
return this.map.delete(this.normalizeUri(uri)); | ||
} | ||
all() { | ||
return Array.from(this.map.keys()); | ||
} | ||
dispose() { | ||
this.map.clear(); | ||
} | ||
async load(uri) { | ||
const document = await this.resolve(uri); | ||
if (document) { | ||
this.map.set(this.normalizeUri(uri), document); | ||
this.map.set(this.getNormalizedUri(uri), document); | ||
} | ||
@@ -376,0 +362,0 @@ return document; |
{ | ||
"name": "@vuedx/vue-virtual-textdocument", | ||
"version": "0.1.0-alpha.2", | ||
"version": "0.1.0-alpha.3", | ||
"description": "", | ||
@@ -17,3 +17,3 @@ "main": "dist/vue-virtual-textdocument.js", | ||
"dependencies": { | ||
"@vuedx/compiler-sfc": "0.1.0-alpha.2", | ||
"@vuedx/compiler-sfc": "0.1.0-alpha.3", | ||
"vscode-languageserver-textdocument": "^1.0.1", | ||
@@ -20,0 +20,0 @@ "vscode-uri": "^2.1.1" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
80837
865
+ Added@vuedx/compiler-sfc@0.1.0-alpha.3(transitive)
- Removed@vuedx/compiler-sfc@0.1.0-alpha.2(transitive)