vscode-languageclient#Position TypeScript Examples
The following examples show how to use
vscode-languageclient#Position.
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 |
/**
* 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;
}
Example #2
Source File: ALLangServerProxy.ts From vscode-alxmldocumentation with MIT License | 5 votes |
/**
* Retrieve AL Object from Language Server.
* @param docUri Actual Document file path.
* @param pos Actual Position to retrieve AL Object from.
*/
async GetALObjectFromDefinition(docUri: string, pos: Position): Promise<{ ALObject: ALObject | null, Position: Position} | undefined> {
try {
if ((!this.IsALLanguageClient()) || (!this.langClient)) {
throw new Error(`Fatal error: Unable to contact language server.`);
}
var __awaiter : any = (this && __awaiter) || function (thisArg: any, _arguments: any, P: PromiseConstructor, generator: { [x: string]: (arg0: any) => any; next: (arg0: any) => any; apply: any; }) {
function adopt(value: unknown) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value: any) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value: any) { try { step(generator['throw'](value)); } catch (e) { reject(e); } }
function step(result: any) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
// Execute AL Go to Definition
let alDefinition: Location | undefined = await this.ALGoToDefinition(docUri, pos).then((result: any) => __awaiter(this, void 0, void 0, function* () {
return Promise.resolve(result);
}));
if ((!alDefinition) || ((alDefinition.range.start.character === 0) && (alDefinition.range.end.character === 0))) {
return undefined;
}
let alSourceCode: string = '';
if (alDefinition.uri.scheme === 'al-preview') {
// For al-preview try get source code from language server.
const request = { Uri: alDefinition.uri.toString() };
alSourceCode = await this.langClient.sendRequest('al/previewDocument', request).then((result: any) => __awaiter(this, void 0, void 0, function* () {
return Promise.resolve(result.content);
}));
} else {
// If file is available just read from filesystem.
alSourceCode = fs.readFileSync(alDefinition.uri.fsPath, 'utf8');
}
let document = Object.assign({});
document.getText = () => alSourceCode;
document.fileName = (alDefinition.uri.scheme === 'al-preview') ? '__symbol__' : alDefinition.uri.fsPath;
let result: { ALObject: ALObject | null, Position: Position} = {
ALObject: await ALSyntaxUtil.GetALObject(document),
Position: alDefinition.range.end
};
return result;
}
catch(ex)
{
console.error(`[GetALObjectFromDefinition] - ${ex} Please report this error at https://github.com/365businessdev/vscode-alxmldocumentation/issues`);
return undefined;
}
}
Example #3
Source File: vscode.ts From ide-vscode with MIT License | 5 votes |
export function toVsPosition(position: Position): VsPosition {
return new VsPosition(position.line, position.character);
}