Skip to content

Commit b406018

Browse files
authored
fix: language server exception for PROC PYTHON (#1322)
1 parent 1aeb873 commit b406018

File tree

4 files changed

+17
-75
lines changed

4 files changed

+17
-75
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,20 @@ All notable changes to this project will be documented in this file.
44

55
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.
66

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

99
### Changed
1010

1111
- Required VS Code version 1.89 at minimum
1212

1313
### Added
1414

15+
- Python language features inside proc python ([#991](https://github.com/sassoftware/vscode-sas-extension/pull/991))
16+
17+
## [v1.12.0] - 2024-11-25
18+
19+
### Added
20+
1521
- Added username and password support for SSH connection type ([#1126](https://github.com/sassoftware/vscode-sas-extension/pull/1126))
1622
- Added support for SAS server for viya connections ([#1203](https://github.com/sassoftware/vscode-sas-extension/pull/1203))
1723
- Enable find in result pane ([#714](https://github.com/sassoftware/vscode-sas-extension/pull/714))

server/src/python/browser/fakeFileSystem.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
// Copyright © 2022-2024, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
/* eslint-disable @typescript-eslint/no-explicit-any */
5-
6-
/* eslint-disable @typescript-eslint/no-this-alias */
7-
84
/*
95
* fakeFileSystem.ts
106
*

server/src/python/utils.ts

Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ export const extractPythonCodes = (
1212
languageService: LanguageServiceProvider,
1313
): string => {
1414
const codeZoneManager = languageService.getCodeZoneManager();
15-
const pythonDocLines = [
16-
"import sas2py #type: ignore",
17-
"SAS = sas2py.SAS2py()",
18-
];
15+
let pythonDocLines = ["import sas2py;SAS = sas2py.SAS2py() #type: ignore"];
1916
const symbols: DocumentSymbol[] = languageService.getDocumentSymbols();
2017
for (let i = 0; i < symbols.length; i++) {
2118
const symbol = symbols[i];
@@ -69,70 +66,15 @@ export const extractPythonCodes = (
6966
end: pythonCodeEnd ?? symbol.range.end,
7067
})
7168
.split("\n");
72-
73-
let startingEmptyLineCount = 0;
74-
let firstNotEmptyLine: string | undefined = undefined;
75-
for (const line of pythonCodeLines) {
76-
if (line.trim().length > 0 && !line.trim().startsWith("#")) {
77-
firstNotEmptyLine = line;
78-
break;
79-
} else {
80-
startingEmptyLineCount++;
81-
}
82-
}
83-
if (startingEmptyLineCount > 0) {
84-
pythonCodeLines.splice(0, startingEmptyLineCount);
85-
pythonCodeStart.line += startingEmptyLineCount;
86-
pythonCodeStart.character = 0;
87-
}
88-
89-
let tailingEmptyLineCount = 0;
90-
for (let i = pythonCodeLines.length - 1; i >= 0; i--) {
91-
if (
92-
pythonCodeLines[i].trim().length === 0 ||
93-
pythonCodeLines[i].trim().startsWith("#")
94-
) {
95-
tailingEmptyLineCount++;
96-
} else {
97-
break;
98-
}
99-
}
100-
if (tailingEmptyLineCount > 0) {
101-
pythonCodeLines.splice(pythonCodeLines.length - tailingEmptyLineCount);
102-
if (pythonCodeEnd) {
103-
pythonCodeEnd.line -= startingEmptyLineCount;
104-
pythonCodeEnd.character =
105-
pythonCodeLines[pythonCodeLines.length - 1].length;
106-
}
107-
}
108-
109-
const shouldAddDummyBlock: boolean =
110-
!!firstNotEmptyLine && [" ", "\t"].includes(firstNotEmptyLine[0]);
11169
const lineGap = pythonCodeStart.line - pythonDocLines.length;
112-
// must be: proc python;submit;<python code>
113-
if (lineGap === 0) {
114-
let line = "if True:";
115-
line += " ".repeat(pythonCodeStart.character - line.length);
116-
line += pythonCodeLines[0];
117-
if (firstNotEmptyLine) {
118-
line += ";pass";
119-
}
120-
pythonDocLines.push(line);
121-
} else {
122-
for (let i = 0; i < lineGap; i++) {
123-
if (shouldAddDummyBlock && i === lineGap - 1) {
124-
pythonDocLines.push("if True:");
125-
} else {
126-
pythonDocLines.push("");
127-
}
128-
}
129-
for (const line of pythonCodeLines) {
130-
pythonDocLines.push(line);
131-
}
132-
if (firstNotEmptyLine) {
133-
pythonDocLines.push("pass");
134-
}
70+
if (lineGap > 0) {
71+
pythonDocLines = pythonDocLines.concat(Array(lineGap).fill(""));
72+
} else if (lineGap === -1 && pythonCodeLines[0] === "") {
73+
// head in one line: proc python; submit;
74+
pythonCodeLines.shift();
13575
}
76+
pythonDocLines = pythonDocLines.concat(pythonCodeLines);
77+
pythonDocLines.push("pass");
13678
}
13779
const pythonDoc = pythonDocLines.join("\n");
13880
return pythonDoc;

server/src/server.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export const runServer = (
321321
);
322322
},
323323
async python(pyrightLanguageService) {
324-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
324+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
325325
return (await pyrightLanguageService.onSignatureHelp(
326326
params,
327327
token,
@@ -648,9 +648,7 @@ export const runServer = (
648648

649649
const isRangeIncluded = (a: Range, b: Range) => {
650650
if (
651-
(b.start.line > a.start.line ||
652-
(b.start.line === a.start.line &&
653-
b.start.character >= a.start.character)) &&
651+
b.start.line > a.start.line &&
654652
(b.end.line < a.end.line ||
655653
(b.end.line === a.end.line && b.end.character <= a.end.character))
656654
) {

0 commit comments

Comments
 (0)