Skip to content

Commit

Permalink
fix: language server exception for PROC PYTHON (#1322)
Browse files Browse the repository at this point in the history
  • Loading branch information
scnwwu authored Dec 17, 2024
1 parent 1aeb873 commit b406018
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 75 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). If you introduce breaking changes, please group them together in the "Changed" section using the **BREAKING:** prefix.

## [v1.12.0] - 2024-11-25
## [Unreleased] - TBD

### Changed

- Required VS Code version 1.89 at minimum

### Added

- Python language features inside proc python ([#991](https://github.com/sassoftware/vscode-sas-extension/pull/991))

## [v1.12.0] - 2024-11-25

### Added

- Added username and password support for SSH connection type ([#1126](https://github.com/sassoftware/vscode-sas-extension/pull/1126))
- Added support for SAS server for viya connections ([#1203](https://github.com/sassoftware/vscode-sas-extension/pull/1203))
- Enable find in result pane ([#714](https://github.com/sassoftware/vscode-sas-extension/pull/714))
Expand Down
4 changes: 0 additions & 4 deletions server/src/python/browser/fakeFileSystem.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// Copyright © 2022-2024, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable @typescript-eslint/no-explicit-any */

/* eslint-disable @typescript-eslint/no-this-alias */

/*
* fakeFileSystem.ts
*
Expand Down
74 changes: 8 additions & 66 deletions server/src/python/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ export const extractPythonCodes = (
languageService: LanguageServiceProvider,
): string => {
const codeZoneManager = languageService.getCodeZoneManager();
const pythonDocLines = [
"import sas2py #type: ignore",
"SAS = sas2py.SAS2py()",
];
let pythonDocLines = ["import sas2py;SAS = sas2py.SAS2py() #type: ignore"];
const symbols: DocumentSymbol[] = languageService.getDocumentSymbols();
for (let i = 0; i < symbols.length; i++) {
const symbol = symbols[i];
Expand Down Expand Up @@ -69,70 +66,15 @@ export const extractPythonCodes = (
end: pythonCodeEnd ?? symbol.range.end,
})
.split("\n");

let startingEmptyLineCount = 0;
let firstNotEmptyLine: string | undefined = undefined;
for (const line of pythonCodeLines) {
if (line.trim().length > 0 && !line.trim().startsWith("#")) {
firstNotEmptyLine = line;
break;
} else {
startingEmptyLineCount++;
}
}
if (startingEmptyLineCount > 0) {
pythonCodeLines.splice(0, startingEmptyLineCount);
pythonCodeStart.line += startingEmptyLineCount;
pythonCodeStart.character = 0;
}

let tailingEmptyLineCount = 0;
for (let i = pythonCodeLines.length - 1; i >= 0; i--) {
if (
pythonCodeLines[i].trim().length === 0 ||
pythonCodeLines[i].trim().startsWith("#")
) {
tailingEmptyLineCount++;
} else {
break;
}
}
if (tailingEmptyLineCount > 0) {
pythonCodeLines.splice(pythonCodeLines.length - tailingEmptyLineCount);
if (pythonCodeEnd) {
pythonCodeEnd.line -= startingEmptyLineCount;
pythonCodeEnd.character =
pythonCodeLines[pythonCodeLines.length - 1].length;
}
}

const shouldAddDummyBlock: boolean =
!!firstNotEmptyLine && [" ", "\t"].includes(firstNotEmptyLine[0]);
const lineGap = pythonCodeStart.line - pythonDocLines.length;
// must be: proc python;submit;<python code>
if (lineGap === 0) {
let line = "if True:";
line += " ".repeat(pythonCodeStart.character - line.length);
line += pythonCodeLines[0];
if (firstNotEmptyLine) {
line += ";pass";
}
pythonDocLines.push(line);
} else {
for (let i = 0; i < lineGap; i++) {
if (shouldAddDummyBlock && i === lineGap - 1) {
pythonDocLines.push("if True:");
} else {
pythonDocLines.push("");
}
}
for (const line of pythonCodeLines) {
pythonDocLines.push(line);
}
if (firstNotEmptyLine) {
pythonDocLines.push("pass");
}
if (lineGap > 0) {
pythonDocLines = pythonDocLines.concat(Array(lineGap).fill(""));
} else if (lineGap === -1 && pythonCodeLines[0] === "") {
// head in one line: proc python; submit;
pythonCodeLines.shift();
}
pythonDocLines = pythonDocLines.concat(pythonCodeLines);
pythonDocLines.push("pass");
}
const pythonDoc = pythonDocLines.join("\n");
return pythonDoc;
Expand Down
6 changes: 2 additions & 4 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export const runServer = (
);
},
async python(pyrightLanguageService) {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
return (await pyrightLanguageService.onSignatureHelp(
params,
token,
Expand Down Expand Up @@ -648,9 +648,7 @@ export const runServer = (

const isRangeIncluded = (a: Range, b: Range) => {
if (
(b.start.line > a.start.line ||
(b.start.line === a.start.line &&
b.start.character >= a.start.character)) &&
b.start.line > a.start.line &&
(b.end.line < a.end.line ||
(b.end.line === a.end.line && b.end.character <= a.end.character))
) {
Expand Down

0 comments on commit b406018

Please sign in to comment.