Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
Support Cairo 0.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Sep 9, 2022
1 parent 69be5c7 commit 9bc9ace
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Cairo language support for StarkNet in VS Code",
"author": "Eric Lau",
"license": "EPL-2.0",
"version": "0.0.26",
"version": "0.0.27",
"preview": true,
"icon": "images/logo.png",
"repository": {
Expand Down
4 changes: 4 additions & 0 deletions server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 0.0.9

- Support Cairo 0.10

## 0.0.8

- Support adding custom Cairo paths in settings. ([#41](https://github.com/ericglau/cairo-ls/pull/41))
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cairo-ls",
"description": "Cairo Language Server",
"version": "0.0.8",
"version": "0.0.9",
"author": "Eric Lau",
"license": "EPL-2.0",
"engines": {
Expand Down
26 changes: 13 additions & 13 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ end
let withinImportModule: string | undefined;
for (var i = 0; i < lines.length; i++) {
var line: string = lines[i].trim();
if (line.length == 0 || line.startsWith("#")) { // ignore whitespace or comments
if (line.length == 0 || line.startsWith("//")) { // ignore whitespace or comments
continue;
}
if (line.startsWith("from")) {
Expand Down Expand Up @@ -311,7 +311,7 @@ end
let context: ParsingContext | undefined;
for (var i = 0; i < lines.length; i++) {
let line: string = lines[i].trim();
if (line.length == 0 || line.startsWith("#")) { // ignore whitespace or comments
if (line.length == 0 || line.startsWith("//")) { // ignore whitespace or comments
continue;
}
if (context !== undefined && context.namespace !== undefined) {
Expand Down Expand Up @@ -352,19 +352,19 @@ end
}

if (startsWith(line, 'struct')) {
pushDefinitionIfFound(line, importName, moduleUrl, ":", STRUCT);
pushDefinitionIfFound(line, importName, moduleUrl, "{", STRUCT);
}

if (startsWith(line, 'namespace')) {
// get namespace from line
const searchNamespace = line.substring('namespace'.length, line.lastIndexOf(':')).trim();
const searchNamespace = line.substring('namespace'.length, line.lastIndexOf('{')).trim();
context = { namespace: searchNamespace };
connection.console.log(`Going into namespace: ${context.namespace}`);

const [ namespace ] = wordWithDot.split('.');
// if we are hovering over the namespace portion in namespace.function, add the namespace definition from the imported module
if (word === namespace) {
pushDefinitionIfFound(line, importName, moduleUrl, ":", NAMESPACE);
pushDefinitionIfFound(line, importName, moduleUrl, "{", NAMESPACE);
}
}
}
Expand All @@ -375,7 +375,7 @@ end
let lines = textDocumentContents.split('\n');
for (var i = 0; i < lines.length; i++) {
let line: string = lines[i].trim();
if (line.length == 0 || line.startsWith("#")) { // ignore whitespace or comments
if (line.length == 0 || line.startsWith("//")) { // ignore whitespace or comments
continue;
}
if (line.startsWith("func") && line.length > 5 && line.charAt(4).match(/\s/)) { // look for functions
Expand Down Expand Up @@ -758,7 +758,7 @@ function getPythonPackageDir(basePath: string) {
} else {
continue;
}
} else if (line.startsWith("#")) {
} else if (line.startsWith("//")) {
continue;
}
if (line === '[options.packages.find]') {
Expand Down Expand Up @@ -818,7 +818,7 @@ function getCompileCommand(settings: CairoLSSettings, tempFiles: TempFiles, text
var directivesFound: boolean = false;
for (var i = 0; i < lines.length; i++) {
var line: string = lines[i].trim();
if (line.length == 0 || line.startsWith("#")) { // ignore whitespace or comments
if (line.length == 0 || line.startsWith("//")) { // ignore whitespace or comments
continue;
}
if (line.startsWith("%")) {
Expand Down Expand Up @@ -1066,8 +1066,8 @@ enum SyntaxType {
ImportKeyword, // from <moduleName>
ImportFunction, // from <moduleName> import
ImportFunctionP, // from <moduleName> import ( ... )
FunctionDecl, // between "func" and ":"
Function, // between ":" and "end"
FunctionDecl, // between "func" and "{"
Function, // between "{" and "end"
WithAttr, // with_attr
Base // file level
}
Expand Down Expand Up @@ -1275,12 +1275,12 @@ connection.onCompletion(
}

// Capture function declaration
if (line.trimLeft().startsWith("func") && !line.includes(":")) {
if (line.trimLeft().startsWith("func") && !line.includes("{")) {
return SyntaxType.FunctionDecl;
}

// Capture function body
if (lastType === SyntaxType.FunctionDecl && line.trimRight().endsWith(":")) {
if (lastType === SyntaxType.FunctionDecl && line.trimRight().endsWith("{")) {
return SyntaxType.Function;
}

Expand Down Expand Up @@ -1331,7 +1331,7 @@ function getModuleNameFromImportPosition(textDocPositionParams: TextDocumentPosi
let importItems: Set<string> = new Set<string>(); // keep a set of unique entries
for (var i = 0; i < lines.length; i++) {
let line: string = lines[i].trim();
if (line.length == 0 || line.startsWith("#")) { // ignore whitespace or comments
if (line.length == 0 || line.startsWith("//")) { // ignore whitespace or comments
continue;
}
const FUNC = "func";
Expand Down

0 comments on commit 9bc9ace

Please sign in to comment.