Fix null ref error in query history (#8304)

* Fix null ref error in query history

* Add null check
This commit is contained in:
Charles Gagnon
2019-11-12 13:38:58 -08:00
committed by GitHub
parent 0ae525cbd5
commit ddddf3beb4

View File

@@ -52,11 +52,14 @@ export class QueryHistoryService extends Disposable implements IQueryHistoryServ
const uri: URI = URI.parse(e.uri);
// VS Range is 1 based so offset values by 1. The endLine we get back from SqlToolsService is incremented
// by 1 from the original input range sent in as well so take that into account and don't modify
const text: string = _modelService.getModel(uri).getValueInRange(new Range(
e.queryInfo.selection[0].startLine + 1,
e.queryInfo.selection[0].startColumn + 1,
e.queryInfo.selection[0].endLine,
e.queryInfo.selection[0].endColumn + 1));
const text: string = e.queryInfo.selection && e.queryInfo.selection.length > 0 ?
_modelService.getModel(uri).getValueInRange(new Range(
e.queryInfo.selection[0].startLine + 1,
e.queryInfo.selection[0].startColumn + 1,
e.queryInfo.selection[0].endLine,
e.queryInfo.selection[0].endColumn + 1)) :
// If no specific selection get the entire text
_modelService.getModel(uri).getValue();
const newInfo = new QueryHistoryInfo(text, _connectionManagementService.getConnectionProfile(e.uri), new Date(), QueryStatus.Succeeded);