Skip to content

Commit

Permalink
Fixes #344
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-bsaviano committed Aug 30, 2024
1 parent b854b00 commit febc7f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [2.6.1] - 2024-08-30
- Fix issue [#344](https://github.com/intersystems/language-server/issues/344): Prevent errors during hover when no data was returned from the server

## [2.6.0] - 2024-08-29
- Fix issue [#329](https://github.com/intersystems/language-server/issues/329): Support Unix platforms that don't have the `en_US.UTF-8` locale
- Fix issue [#336](https://github.com/intersystems/language-server/issues/336): Add intellisense for variables set to the returned value of a method, or a property, with a declared type
Expand Down
8 changes: 7 additions & 1 deletion client/src/makeRESTRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,13 @@ export async function makeRESTRequest(method: "GET"|"POST", api: number, path: s
return respdata;
}
} catch (error) {
console.log(error);
client.warn(`Error making REST request ${method} ${path}: ${
typeof error == "string"
? error
: error instanceof Error
? error.toString()
: JSON.stringify(error)
}`);
return undefined;
}
};
12 changes: 6 additions & 6 deletions server/src/providers/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export async function onHover(params: TextDocumentPositionParams): Promise<Hover
parameters: [normalizedname]
};
const respdata = await makeRESTRequest("POST",1,"/action/query",server,querydata);
if (respdata !== undefined && respdata.data.result.content !== undefined && respdata.data.result.content.length === 1) {
if (Array.isArray(respdata?.data?.result?.content) && respdata.data.result.content.length == 1) {
// The class was found
return {
contents: {
Expand Down Expand Up @@ -309,7 +309,7 @@ export async function onHover(params: TextDocumentPositionParams): Promise<Hover
mode: maccon.mode
};
const exprespdata = await makeRESTRequest("POST",2,"/action/getmacroexpansion",server,expquerydata);
if (exprespdata !== undefined && exprespdata.data.result.content.expansion.length > 0) {
if (Array.isArray(exprespdata?.data?.result?.content?.expansion) && exprespdata.data.result.content.expansion.length > 0) {
// We got data back
const exptext = exprespdata.data.result.content.expansion.join(" \n");
if (exptext.slice(0,5) === "ERROR") {
Expand All @@ -324,7 +324,7 @@ export async function onHover(params: TextDocumentPositionParams): Promise<Hover
mode: maccon.mode
};
const defrespdata = await makeRESTRequest("POST",2,"/action/getmacrodefinition",server,defquerydata);
if (defrespdata !== undefined && defrespdata.data.result.content.definition.length > 0) {
if (Array.isArray(defrespdata?.data?.result?.content?.definition) && defrespdata.data.result.content.definition.length > 0) {
// The macro definition was found
return {
contents: macroDefToDoc(defrespdata.data.result.content.definition),
Expand Down Expand Up @@ -357,7 +357,7 @@ export async function onHover(params: TextDocumentPositionParams): Promise<Hover
mode: maccon.mode
};
const respdata = await makeRESTRequest("POST",2,"/action/getmacrodefinition",server,inputdata);
if (respdata !== undefined && respdata.data.result.content.definition.length > 0) {
if (Array.isArray(respdata?.data?.result?.content?.definition) && respdata.data.result.content.definition.length > 0) {
// The macro definition was found
return {
contents: macroDefToDoc(respdata.data.result.content.definition),
Expand Down Expand Up @@ -902,7 +902,7 @@ export async function onHover(params: TextDocumentPositionParams): Promise<Hover
parameters: [normalizedname]
};
const respdata = await makeRESTRequest("POST",1,"/action/query",server,querydata);
if (respdata !== undefined && respdata.data.result.content.length === 1) {
if (Array.isArray(respdata?.data?.result?.content) && respdata.data.result.content.length == 1) {
// The class was found
return {
contents: {
Expand Down Expand Up @@ -1124,7 +1124,7 @@ export async function onHover(params: TextDocumentPositionParams): Promise<Hover
parameters: [varClass]
};
const respdata = await makeRESTRequest("POST",1,"/action/query",server,querydata);
if (respdata !== undefined && respdata.data.result.content !== undefined && respdata.data.result.content.length === 1) {
if (Array.isArray(respdata?.data?.result?.content) && respdata.data.result.content.length == 1) {
// The class was found
return {
contents: {
Expand Down

0 comments on commit febc7f4

Please sign in to comment.