1 | import { TextDocumentContentChangeEvent } from 'vscode-languageserver-protocol';
|
2 | import URI from '../common/uri';
|
3 | import { ContributionProvider } from './contribution-provider';
|
4 | import { Event, Emitter } from './event';
|
5 | import { Disposable } from './disposable';
|
6 | import { MaybePromise } from './types';
|
7 | import { CancellationToken } from './cancellation';
|
8 | import { ApplicationError } from './application-error';
|
9 | import { ReadableStream, Readable } from './stream';
|
10 | import { SyncReferenceCollection, Reference } from './reference';
|
11 | import { MarkdownString } from './markdown-rendering';
|
12 | export interface ResourceVersion {
|
13 | }
|
14 | export interface ResourceReadOptions {
|
15 | encoding?: string;
|
16 | }
|
17 | export interface ResourceSaveOptions {
|
18 | encoding?: string;
|
19 | overwriteEncoding?: boolean;
|
20 | version?: ResourceVersion;
|
21 | }
|
22 | export interface Resource extends Disposable {
|
23 | readonly uri: URI;
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | readonly version?: ResourceVersion | undefined;
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | readonly encoding?: string | undefined;
|
38 | readonly onDidChangeReadOnly?: Event<boolean | MarkdownString>;
|
39 | readonly readOnly?: boolean | MarkdownString;
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | readContents(options?: ResourceReadOptions): Promise<string>;
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | readStream?(options?: ResourceReadOptions): Promise<ReadableStream<string>>;
|
58 | |
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | saveContents?(content: string, options?: ResourceSaveOptions): Promise<void>;
|
70 | |
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | saveStream?(content: Readable<string>, options?: ResourceSaveOptions): Promise<void>;
|
82 | |
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | saveContentChanges?(changes: TextDocumentContentChangeEvent[], options?: ResourceSaveOptions): Promise<void>;
|
93 | readonly onDidChangeContents?: Event<void>;
|
94 | guessEncoding?(): Promise<string | undefined>;
|
95 | }
|
96 | export declare namespace Resource {
|
97 | interface SaveContext {
|
98 | contentLength: number;
|
99 | content: string | Readable<string>;
|
100 | changes?: TextDocumentContentChangeEvent[];
|
101 | options?: ResourceSaveOptions;
|
102 | }
|
103 | function save(resource: Resource, context: SaveContext, token?: CancellationToken): Promise<void>;
|
104 | function trySaveContentChanges(resource: Resource, context: SaveContext): Promise<boolean>;
|
105 | function shouldSaveContent(resource: Resource, { contentLength, changes }: SaveContext): boolean;
|
106 | }
|
107 | export declare namespace ResourceError {
|
108 | const NotFound: ApplicationError.Constructor<-40000, {
|
109 | uri: URI;
|
110 | }>;
|
111 | const OutOfSync: ApplicationError.Constructor<-40001, {
|
112 | uri: URI;
|
113 | }>;
|
114 | }
|
115 | export declare const ResourceResolver: unique symbol;
|
116 | export interface ResourceResolver {
|
117 | |
118 |
|
119 |
|
120 | resolve(uri: URI): MaybePromise<Resource>;
|
121 | }
|
122 | export declare const ResourceProvider: unique symbol;
|
123 | export type ResourceProvider = (uri: URI) => Promise<Resource>;
|
124 | export declare class DefaultResourceProvider {
|
125 | protected readonly resolversProvider: ContributionProvider<ResourceResolver>;
|
126 | constructor(resolversProvider: ContributionProvider<ResourceResolver>);
|
127 | /**
|
128 | * Reject if a resource cannot be provided.
|
129 | */
|
130 | get(uri: URI): Promise<Resource>;
|
131 | }
|
132 | export declare class MutableResource implements Resource {
|
133 | readonly uri: URI;
|
134 | private contents;
|
135 | constructor(uri: URI);
|
136 | dispose(): void;
|
137 | readContents(): Promise<string>;
|
138 | saveContents(contents: string): Promise<void>;
|
139 | protected readonly onDidChangeContentsEmitter: Emitter<void>;
|
140 | readonly onDidChangeContents: Event<void>;
|
141 | protected fireDidChangeContents(): void;
|
142 | }
|
143 | export declare class ReferenceMutableResource implements Resource {
|
144 | protected reference: Reference<MutableResource>;
|
145 | constructor(reference: Reference<MutableResource>);
|
146 | get uri(): URI;
|
147 | get onDidChangeContents(): Event<void>;
|
148 | dispose(): void;
|
149 | readContents(): Promise<string>;
|
150 | saveContents(contents: string): Promise<void>;
|
151 | }
|
152 | export declare class InMemoryResources implements ResourceResolver {
|
153 | protected readonly resources: SyncReferenceCollection<string, MutableResource>;
|
154 | add(uri: URI, contents: string): Resource;
|
155 | update(uri: URI, contents: string): Resource;
|
156 | resolve(uri: URI): Resource;
|
157 | protected acquire(uri: string): ReferenceMutableResource;
|
158 | }
|
159 | export declare const MEMORY_TEXT = "mem-txt";
|
160 |
|
161 |
|
162 |
|
163 | export declare class InMemoryTextResource implements Resource {
|
164 | readonly uri: URI;
|
165 | constructor(uri: URI);
|
166 | readContents(options?: {
|
167 | encoding?: string | undefined;
|
168 | } | undefined): Promise<string>;
|
169 | dispose(): void;
|
170 | }
|
171 | /**
|
172 | * ResourceResolver implementation for 'mem-txt' URI scheme.
|
173 | */
|
174 | export declare class InMemoryTextResourceResolver implements ResourceResolver {
|
175 | resolve(uri: URI): MaybePromise<Resource>;
|
176 | }
|
177 | export declare const UNTITLED_SCHEME = "untitled";
|
178 | export declare class UntitledResourceResolver implements ResourceResolver {
|
179 | protected readonly resources: Map<string, UntitledResource>;
|
180 | has(uri: URI): boolean;
|
181 | resolve(uri: URI): Promise<UntitledResource>;
|
182 | createUntitledResource(content?: string, extension?: string, uri?: URI): Promise<UntitledResource>;
|
183 | createUntitledURI(extension?: string, parent?: URI): URI;
|
184 | }
|
185 | export declare class UntitledResource implements Resource {
|
186 | private resources;
|
187 | uri: URI;
|
188 | private content?;
|
189 | protected readonly onDidChangeContentsEmitter: Emitter<void>;
|
190 | get onDidChangeContents(): Event<void>;
|
191 | constructor(resources: Map<string, UntitledResource>, uri: URI, content?: string | undefined);
|
192 | dispose(): void;
|
193 | readContents(options?: {
|
194 | encoding?: string | undefined;
|
195 | } | undefined): Promise<string>;
|
196 | saveContents(content: string, options?: {
|
197 | encoding?: string;
|
198 | overwriteEncoding?: boolean;
|
199 | }): Promise<void>;
|
200 | protected fireDidChangeContents(): void;
|
201 | get version(): ResourceVersion | undefined;
|
202 | get encoding(): string | undefined;
|
203 | }
|
204 | /**
|
205 | * @deprecated Since 1.27.0. Please use `UntitledResourceResolver.createUntitledURI` instead.
|
206 | */
|
207 | export declare function createUntitledURI(extension?: string, parent?: URI): URI;
|
208 | //# sourceMappingURL=resource.d.ts.map |
\ | No newline at end of file |