Skip to content

Commit 73aebf1

Browse files
committed
feat(vars): add varaible model
Signed-off-by: Rithul Kamesh <[email protected]>
1 parent ec7cb92 commit 73aebf1

File tree

3 files changed

+103
-22
lines changed

3 files changed

+103
-22
lines changed

.devcontainer/Dockerfile

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
1-
# FROM mcr.microsoft.com/devcontainers/java:1-21-bullseye
2-
FROM ubuntu:22.04
1+
FROM mcr.microsoft.com/devcontainers/base:ubuntu-22.04
32

4-
# Add any tools that are needed beyond Java
5-
RUN apt-get update && \
6-
apt-get install -y sudo sed vim git make gcc zlib1g-dev zip unzip tree curl wget jq && \
7-
apt-get autoremove -y && \
8-
apt-get clean -y
9-
10-
# Create a user for development
3+
# Arguments for user creation
114
ARG USERNAME=vscode
125
ARG USER_UID=1000
136
ARG USER_GID=$USER_UID
147

15-
# Create the user with passwordless sudo privileges
8+
# Install necessary packages
9+
# Combine RUN commands and clean up in the same layer to reduce image size
10+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
11+
&& apt-get -y install --no-install-recommends \
12+
sudo \
13+
sed \
14+
vim \
15+
git \
16+
make \
17+
gcc \
18+
zlib1g-dev \
19+
zip \
20+
unzip \
21+
tree \
22+
curl \
23+
wget \
24+
jq \
25+
build-essential \
26+
&& apt-get autoremove -y \
27+
&& apt-get clean -y \
28+
&& rm -rf /var/lib/apt/lists/*
29+
30+
# Create the user with sudo privileges
1631
RUN groupadd --gid $USER_GID $USERNAME \
1732
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \
18-
&& usermod -aG sudo $USERNAME \
1933
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
20-
&& chmod 0440 /etc/sudoers.d/$USERNAME \
21-
&& chown -R $USERNAME:$USERNAME /home/$USERNAME
22-
23-
WORKDIR /codeanalyzer-rs
34+
&& chmod 0440 /etc/sudoers.d/$USERNAME
2435

36+
# Set up Rust for the vscode user
2537
USER $USERNAME
38+
WORKDIR /workspaces/codeanalyzer-rs
39+
40+
# Install Rust using rustup
41+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
42+
&& . $HOME/.cargo/env \
43+
&& rustup install nightly \
44+
&& rustup default nightly \
45+
&& rustup component add rustfmt clippy
2646

27-
# Install Java and Gradle via SDKMan
28-
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
47+
# Update PATH for Rust
48+
ENV PATH="/home/${USERNAME}/.cargo/bin:${PATH}"
2949

30-
# This SHELL command is needed to run using `source`
31-
SHELL ["/bin/bash", "-c"]
32-
RUN rustup install nightly && \
33-
rustup default nightly
50+
# Pre-build common Rust tools to speed up container startup
51+
RUN cargo install cargo-watch cargo-edit

src/entities/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod callsite;
33
pub mod lifetime;
44
pub mod param;
55
pub mod rtype;
6-
6+
pub mod variables;
77
#[derive(Debug, Clone, PartialEq)]
88
pub enum RustVisibility {
99
Public,

src/entities/variables.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use crate::entities::{RustVisibility, attr::RustAttribute, rtype::RustType};
2+
/// Represents a variable declaration in Rust.
3+
///
4+
/// # Fields
5+
///
6+
/// * `name` - The name of the variable
7+
/// * `type_info` - Optional type information of the variable
8+
/// * `is_mut` - Flag indicating if the variable is mutable
9+
/// * `is_static` - Flag indicating if the variable is static
10+
/// * `is_const` - Flag indicating if the variable is a constant
11+
/// * `initializer` - Optional initialization expression as a string
12+
/// * `visibility` - Visibility level of the variable (public, private, etc.)
13+
/// * `doc_comment` - Optional documentation comment associated with the variable
14+
/// * `attributes` - Vector of attributes associated with the variable
15+
/// * `line_number` - Line number where the variable is declared in the source code
16+
///
17+
/// # Examples
18+
///
19+
/// ```
20+
/// let var = RustVariableDeclaration::new(String::from("my_var"), 1);
21+
/// assert_eq!(var.name, "my_var");
22+
/// assert_eq!(var.line_number, 1);
23+
/// ```
24+
#[derive(Debug, Clone)]
25+
pub struct RustVariableDeclaration {
26+
/// The name of the variable
27+
pub name: String,
28+
/// The type of the variable (optional)
29+
pub type_info: Option<RustType>,
30+
/// Whether the variable is mutable
31+
pub is_mut: bool,
32+
/// Whether the variable is static
33+
pub is_static: bool,
34+
/// Whether the variable is const
35+
pub is_const: bool,
36+
/// The initializer expression (optional)
37+
pub initializer: Option<String>,
38+
/// The visibility of the variable
39+
pub visibility: RustVisibility,
40+
/// Documentation comment (optional)
41+
pub doc_comment: Option<String>,
42+
/// Associated attributes
43+
pub attributes: Vec<RustAttribute>,
44+
/// Line number in source code
45+
pub line_number: usize,
46+
}
47+
48+
impl RustVariableDeclaration {
49+
pub fn new(name: String, line_number: usize) -> Self {
50+
Self {
51+
name,
52+
type_info: None,
53+
is_mut: false,
54+
is_static: false,
55+
is_const: false,
56+
initializer: None,
57+
visibility: RustVisibility::Private,
58+
doc_comment: None,
59+
attributes: Vec::new(),
60+
line_number,
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)