vscode-languageclient#CancellationTokenSource TypeScript Examples

The following examples show how to use vscode-languageclient#CancellationTokenSource. 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: ALLangServerProxy.ts    From vscode-alxmldocumentation with MIT License 5 votes vote down vote up
/**
     * Perform go-to-definition call.
     * @param docUri URI of the source document.
     * @param pos Position to perform go-to-definition on.
     */
    async ALGoToDefinition(docUri: string, pos: Position) : Promise<Location | undefined> {
        let docPos : Location | undefined = undefined;
        try {
            this.IsALLanguageClient();
            if (!this.langClient) {
                return undefined;
            }

            let launchConfiguration = await this.GetFirstLaunchConfiguration();

            if (launchConfiguration) {
                let docPosTemp : any = await this.langClient.sendRequest<any>('al/gotodefinition', {
                    launchConfiguration : launchConfiguration,
                    textDocumentPositionParams : {
                        textDocument : {
                            uri : docUri.toString()
                        },
                        position : {
                            line : pos.line,
                            character : pos.character
                        }
                    },
                    context : undefined
                }, new CancellationTokenSource().token);

                if (docPosTemp) {
                    docPos = new Location(
                        Uri.parse(docPosTemp.uri),
                        new Range(
                            docPosTemp.range.start.line, 
                            docPosTemp.range.start.character,
                            docPosTemp.range.end.line, 
                            docPosTemp.range.end.character
                            )
                        );                    
                }
            }
        }   
        catch (ex) {
            console.debug(ex.message);
            return undefined;
        }    

        return docPos; 
    }