vscode#Disposable TypeScript Examples

The following examples show how to use vscode#Disposable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodeLensController.ts    From vscode-debug-leetcode with MIT License 6 votes vote down vote up
class CodeLensController implements Disposable {
    private internalProvider: CustomCodeLensProvider;
    private registeredProvider: Disposable | undefined;

    constructor() {
        this.internalProvider = new CustomCodeLensProvider();

        this.registeredProvider = languages.registerCodeLensProvider(
            { scheme: 'file' },
            this.internalProvider,
        );
    }

    public dispose(): void {
        if (this.registeredProvider) {
            this.registeredProvider.dispose();
        }
    }
}
Example #2
Source File: serviceManager.ts    From vscode-ssh with MIT License 6 votes vote down vote up
public init(): Disposable[] {
        if (this.isInit) return []
        const res: Disposable[] = []
        this.provider = new ConnectionProvider(this.context)
        const treeview = vscode.window.createTreeView("github.cweijan.ssh", {
            treeDataProvider: this.provider
        });
        res.push(treeview)
        this.isInit = true
        return res
    }
Example #3
Source File: split-provider.ts    From plugin-vscode with Apache License 2.0 6 votes vote down vote up
/**
 * Configures string split capability for the extension.
 */
export class StringSplitFeature implements Disposable {

    private disposables: Disposable[] = [];
    private provider: StringSplitter;
    private ballerinaExtInstance: BallerinaExtension;

    constructor(provider: StringSplitter, ballerinaExtInstance: BallerinaExtension) {
        this.provider = provider;
        this.ballerinaExtInstance = ballerinaExtInstance;
        workspace.onDidChangeTextDocument(this.provider.updateDocument, this.ballerinaExtInstance, this.disposables);
    }

    dispose() {
        this.disposables.forEach((disposable) => disposable.dispose());
    }
}
Example #4
Source File: utopia-fs.ts    From utopia with MIT License 6 votes vote down vote up
watch(uri: Uri, options: { recursive: boolean; excludes: string[] }): Disposable {
    const path = fromUtopiaURI(uri)
    watch(
      path,
      options.recursive,
      this.notifyFileCreated.bind(this),
      this.notifyFileChanged.bind(this),
      this.notifyFileDeleted.bind(this),
      () => {
        /* no op */
      },
    )

    return new Disposable(() => {
      stopWatching(path, options.recursive)
    })
  }
Example #5
Source File: extension.ts    From ide-vscode with MIT License 6 votes vote down vote up
private async getLanguageServerVersionAfterStartup(): Promise<string> {
    let versionRegistration: Disposable | undefined;
    const version = await PromiseAny([
      new Promise<string>(resolve => {
        versionRegistration = this.client!.onServerVersion(version => resolve(version));
      }),
      // Fallback to unknown in case the server does not report the version.
      timeout(DafnyVersionTimeoutMs, LanguageServerConstants.UnknownVersion)
    ]);
    versionRegistration!.dispose();
    return version;
  }
Example #6
Source File: registerCommand.ts    From joplin-utils with MIT License 6 votes vote down vote up
/**
 * 注册一个 vscode 的命令,封装日志相关的处理
 * @param command
 * @param callback
 * @param thisArg
 */
export function registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable {
  return vscode.commands.registerCommand(
    command,
    async (...args: any[]) => {
      try {
        return await callback(...args)
      } catch (err) {
        logger.error('command error: ', command, err)
        throw err
      }
    },
    thisArg,
  )
}
Example #7
Source File: lsp-commands.ts    From vscode-microprofile with Apache License 2.0 6 votes vote down vote up
/**
 * Registers the `microprofile.command.open.uri` command.
 * This command gives the capability to open the given uri of the command.
 */
export function registerOpenURICommand(): Disposable {
  return commands.registerCommand(CommandKind.COMMAND_OPEN_URI, (uri) => {
    commands.executeCommand('vscode.open', Uri.parse(uri));
  });
}
Example #8
Source File: tempFolder.ts    From vscode-lean4 with Apache License 2.0 6 votes vote down vote up
export class TempFolder implements Disposable {
    folder : string;

    constructor(prefix: string){
        this.folder = fs.mkdtempSync(join(os.tmpdir(), prefix))
    }

    createFile(fileName : string, data : string) : string {
        const path = join(this.folder, fileName)
        fs.writeFileSync(path, data, { encoding: 'utf8'});
        return path;
    }

    dispose(): void {
        if (this.folder){
            try {
                fs.rmdirSync(this.folder, {
                    recursive: true
                })
            } catch {}
        }
    }
}
Example #9
Source File: TwoWayBinding.ts    From dendron with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
   * A view or a controller can bind a callback to the viewmodel with this
   * function
   * @param callback
   * @param thisArg
   * @returns
   */
  bind(
    callback: (newValue: T, previous: T) => void,
    thisArg?: any
  ): Disposable {
    return this._emitter.event((data) => {
      const bound = callback.bind(thisArg);
      bound(data.newValue, data.previous);
    });
  }
Example #10
Source File: autorunDisposable.ts    From vscode-lean4 with Apache License 2.0 6 votes vote down vote up
/**
 * Like `autorun`, but more suited for working with Disposables.
 * The `disposables` passed to `reaction` will be disposed when the reaction is triggered again.
 */
export function autorunDisposable(
	reaction: (disposables: Disposable[]) => void
): Disposable {
	let lastDisposable = new Array<Disposable>();
	return {
		dispose: autorun(() => {
			for (const d of lastDisposable) {
				d.dispose();
			}
			lastDisposable = [];
			reaction(lastDisposable);
		}),
	};
}
Example #11
Source File: registerFailableCommand.ts    From vscode-drawio with GNU General Public License v3.0 6 votes vote down vote up
export function registerFailableCommand(
	commandName: string,
	commandFn: (...args: any[]) => any
): Disposable {
	return commands.registerCommand(commandName, async (...args: any[]) => {
		try {
			return await commandFn(...args);
		} catch (e) {
			window.showErrorMessage("The command failed: " + e.message);
			return false;
		}
	});
}
Example #12
Source File: index.ts    From vscode-dbt-power-user with MIT License 6 votes vote down vote up
@provideSingleton(AutocompletionProviders)
export class AutocompletionProviders implements Disposable {
  private disposables: Disposable[] = [];
  constructor(
    private macroAutocompletionProvider: MacroAutocompletionProvider,
    private modelAutocompletionProvider: ModelAutocompletionProvider,
    private sourceAutocompletionProvider: SourceAutocompletionProvider
  ) {
    this.disposables.push(
      languages.registerCompletionItemProvider(
        DBTPowerUserExtension.DBT_MODE,
        this.macroAutocompletionProvider
      ),
      languages.registerCompletionItemProvider(
        DBTPowerUserExtension.DBT_MODE,
        this.modelAutocompletionProvider,
        "'",
        '"'
      ),
      languages.registerCompletionItemProvider(
        DBTPowerUserExtension.DBT_MODE,
        this.sourceAutocompletionProvider,
        "'",
        '"'
      ),
    );
  }

  dispose() {
    this.disposables.forEach(disposable => disposable.dispose());
  }
}
Example #13
Source File: DoComment.ts    From vscode-alxmldocumentation with MIT License 6 votes vote down vote up
/**
     * DoComment constructor
     */
    constructor() {       
        const subscriptions: Disposable[] = [];

        workspace.onDidChangeTextDocument(event => {            
            const activeEditor = window.activeTextEditor;

            if (event.document.languageId !== 'al') {
                return;
            }

            if (activeEditor && event.document === activeEditor.document) {
                this.DoComment(activeEditor, event.contentChanges[0]);
            }
        }, this, subscriptions);
        
        this.disposable = Disposable.from(...subscriptions);
    }
Example #14
Source File: index.ts    From vscode-dbt-power-user with MIT License 5 votes vote down vote up
private disposables: Disposable[] = [];
Example #15
Source File: CodeLensController.ts    From vscode-debug-leetcode with MIT License 5 votes vote down vote up
private registeredProvider: Disposable | undefined;
Example #16
Source File: WebviewERD.ts    From vuerd-vscode with MIT License 5 votes vote down vote up
private disposables: Disposable[] = [];
Example #17
Source File: ObjectIdConfigWatcher.ts    From al-objid with MIT License 5 votes vote down vote up
private readonly _edited: Disposable;
Example #18
Source File: extension.ts    From vscode-todo-md with MIT License 5 votes vote down vote up
static changeActiveTextEditorDisposable: Disposable;
Example #19
Source File: CompiledCodeContentProvider.ts    From language-tools with MIT License 5 votes vote down vote up
private subscriptions: Disposable[] = [];
Example #20
Source File: sqlFluffLinter.ts    From vscode-sqlfluff with MIT License 5 votes vote down vote up
public activate(subscriptions: Disposable[]) {
		let provider = new LintingProvider(this);
		provider.activate(subscriptions);
	}
Example #21
Source File: extension.ts    From vscode-crestron-splus with GNU General Public License v3.0 5 votes vote down vote up
taskProvider: Disposable | undefined
Example #22
Source File: listener.ts    From vscode-discord with MIT License 5 votes vote down vote up
private disposables: Disposable[] = [];
Example #23
Source File: lsp-commands.ts    From vscode-microprofile with Apache License 2.0 5 votes vote down vote up
/**
 * Registers the `CommandKind.COMMAND_REFERENCES` command
 */
export function registerReferencesCommand(): Disposable {
  return commands.registerCommand(CommandKind.COMMAND_REFERENCES, () => {
    // not yet implemented
  });
}
Example #24
Source File: leanpkg.ts    From vscode-lean4 with Apache License 2.0 5 votes vote down vote up
private subscriptions: Disposable[] = [];
Example #25
Source File: query-console.ts    From vscode-q with MIT License 5 votes vote down vote up
private _disposables: Disposable[] = [];
Example #26
Source File: index.ts    From vscode-dbt-power-user with MIT License 5 votes vote down vote up
private disposables: Disposable[] = [];
Example #27
Source File: TextDocumentService.ts    From dendron with GNU Affero General Public License v3.0 5 votes vote down vote up
_textDocumentEventHandle: Disposable;
Example #28
Source File: workspace.ts    From vscode-code-review with MIT License 5 votes vote down vote up
private setReviewFileSelectedCsvRegistration!: Disposable;
Example #29
Source File: BacklinksTreeDataProvider.ts    From dendron with GNU Affero General Public License v3.0 5 votes vote down vote up
private _onDidChangeActiveTextEditorDisposable: Disposable | undefined;