-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
182 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { TextDocument } from "./text-document"; | ||
|
||
export class CacheDocuments { | ||
private _documents: Map<string, TextDocument>; | ||
|
||
constructor() { | ||
this._documents = new Map<string, TextDocument>(); | ||
} | ||
|
||
get(uri: string): TextDocument | undefined { | ||
return this._documents.get(uri); | ||
} | ||
set(uri: string, document: TextDocument) { | ||
this._documents.set(uri, document); | ||
return this; | ||
} | ||
delete(uri: string) { | ||
return this._documents.delete(uri); | ||
} | ||
/** | ||
* Only add the document to the cache if the document already has the document | ||
* @param uri | ||
* @param document | ||
* @returns | ||
*/ | ||
update(uri: string, document: TextDocument) { | ||
if (this._documents.has(uri)) { | ||
this._documents.set(uri, document); | ||
} | ||
|
||
return this; | ||
} | ||
clear() { | ||
this._documents.clear(); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { FileChangeType, FileEvent } from "vscode-languageserver-protocol"; | ||
import { TextDocument } from "./text-document"; | ||
|
||
export interface DocumentEvent extends FileEvent { | ||
document: TextDocument | undefined; | ||
} | ||
|
||
export interface DocumenterGetter { | ||
get(uri: string): TextDocument | undefined; | ||
} | ||
|
||
export class LazyDocumentEvent implements DocumentEvent { | ||
private _document: TextDocument | undefined; | ||
private _uri: string; | ||
private _type: FileChangeType; | ||
private _getter: DocumenterGetter; | ||
|
||
constructor(getter: DocumenterGetter, uri: string, type: FileChangeType) { | ||
this._getter = getter; | ||
this._uri = uri; | ||
this._type = type; | ||
this._document = undefined; | ||
} | ||
get uri(): string { | ||
return this._uri; | ||
} | ||
get type(): FileChangeType { | ||
return this._type; | ||
} | ||
|
||
get document(): TextDocument | undefined { | ||
if (this._document) return this._document; | ||
|
||
this._document = this._getter.get(this._uri); | ||
return this._document; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters