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